From 6aa562cdb6c7f69fbf31518458d834fdc612f2da Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Sat, 23 Nov 2019 00:46:15 -0500
Subject: [PATCH 65/95] FIXME: WIP on conversion from --analyzer to -fanalyzer
 (has failing testcase)

---
 gcc/analyzer/Make-plugin.in                        |  2 +-
 gcc/common.opt                                     |  6 ++--
 gcc/doc/invoke.texi                                | 36 +++++++++++-----------
 gcc/gcc.c                                          |  5 +--
 gcc/testsuite/gcc.dg/analyzer/analyzer.exp         |  2 +-
 gcc/testsuite/gcc.dg/analyzer/disabling.c          | 10 ++++++
 gcc/testsuite/gcc.dg/analyzer/malloc-dce.c         |  2 +-
 .../gcc.dg/analyzer/malloc-ipa-8-double-free.c     |  2 +-
 .../gcc.dg/analyzer/malloc-ipa-8-unchecked.c       |  2 +-
 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-9.c       |  2 +-
 .../gcc.dg/analyzer/malloc-macro-inline-events.c   |  2 +-
 .../gcc.dg/analyzer/malloc-macro-separate-events.c |  2 +-
 gcc/testsuite/lib/target-supports.exp              |  2 +-
 13 files changed, 43 insertions(+), 32 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/disabling.c

diff --git a/gcc/analyzer/Make-plugin.in b/gcc/analyzer/Make-plugin.in
index 08c96f1..08f58f4 100644
--- a/gcc/analyzer/Make-plugin.in
+++ b/gcc/analyzer/Make-plugin.in
@@ -105,7 +105,7 @@ $(ANALYZER_PLUGIN_SO): $(analyzer_OBJS) $(plugin_builddir)
 # at each stage of the build:
 selftest-analyzer: s-selftest-analyzer
 
-ANALYZER_SELFTEST_FLAGS = -xc $(SELFTEST_FLAGS) --analyzer
+ANALYZER_SELFTEST_FLAGS = -xc $(SELFTEST_FLAGS) -fanalyzer
 ANALYZER_SELFTEST_DEPS = cc1$(exeext) $(SELFTEST_DEPS) $(ANALYZER_PLUGIN_SO)
 
 # Run the analyzer selftests:
diff --git a/gcc/common.opt b/gcc/common.opt
index 3f6de96..840e9f4 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -266,9 +266,6 @@ Driver Joined Alias(e)
 -extra-warnings
 Common Warning Alias(Wextra)
 
--analyzer
-Driver Var(analyzer_flag)
-
 -for-assembler
 Driver Separate Alias(Xassembler)
 
@@ -992,6 +989,9 @@ fallow-store-data-races
 Common Report Var(flag_store_data_races) Optimization
 Allow the compiler to introduce new data races on stores.
 
+fanalyzer
+Driver Var(flag_analyzer)
+
 fargument-alias
 Common Ignore
 Does nothing. Preserved for backward compatibility.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index caeb9ce..d4b154c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -289,7 +289,7 @@ Objective-C and Objective-C++ Dialects}.
 
 @item Warning Options
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
-@gccoptlist{--analyzer -fsyntax-only  -fmax-errors=@var{n}  -Wpedantic @gol
+@gccoptlist{-fanalyzer -fsyntax-only  -fmax-errors=@var{n}  -Wpedantic @gol
 -pedantic-errors @gol
 -w  -Wextra  -Wall  -Waddress  -Waddress-of-packed-member @gol
 -Waggregate-return  -Waligned-new @gol
@@ -6428,7 +6428,7 @@ equivalent to @option{-Walloca-larger-than=}@samp{SIZE_MAX} or larger.
 @item -Wno-analyzer-double-fclose
 @opindex Wanalyzer-double-fclose
 @opindex Wno-analyzer-double-fclose
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-double-fclose} to disable it.
 
 This diagnostic warns for paths through the code in which a @code{FILE *}
@@ -6437,7 +6437,7 @@ can have @code{fclose} called on it more than once.
 @item -Wno-analyzer-double-free
 @opindex Wanalyzer-double-free
 @opindex Wno-analyzer-double-free
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-double-free} to disable it.
 
 This diagnostic warns for paths through the code in which a pointer
@@ -6446,7 +6446,7 @@ can have @code{free} called on it more than once.
 @item -Wno-analyzer-exposure-through-output-file
 @opindex Wanalyzer-exposure-through-output-file
 @opindex Wno-analyzer-exposure-through-output-file
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-exposure-through-output-file}
 to disable it.
 
@@ -6457,7 +6457,7 @@ security-sensitive value is written to an output file
 @item -Wno-analyzer-file-leak
 @opindex Wanalyzer-file-leak
 @opindex Wno-analyzer-file-leak
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-file-leak}
 to disable it.
 
@@ -6467,7 +6467,7 @@ This diagnostic warns for paths through the code in which a
 @item -Wno-analyzer-free-of-non-heap
 @opindex Wanalyzer-free-of-non-heap
 @opindex Wno-analyzer-free-of-non-heap
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-free-of-non-heap}
 to disable it.
 
@@ -6477,7 +6477,7 @@ is called on a non-heap pointer (e.g. an on-stack buffer, or a global).
 @item -Wno-analyzer-malloc-leak
 @opindex Wanalyzer-malloc-leak
 @opindex Wno-analyzer-malloc-leak
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-malloc-leak}
 to disable it.
 
@@ -6487,7 +6487,7 @@ pointer allocated via @code{malloc} is leaked.
 @item -Wno-analyzer-possible-null-argument
 @opindex Wanalyzer-possible-null-argument
 @opindex Wno-analyzer-possible-null-argument
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-possible-null-argument} to disable it.
 
 This diagnostic warns for paths through the code in which a
@@ -6498,7 +6498,7 @@ value.
 @item -Wno-analyzer-possible-null-dereference
 @opindex Wanalyzer-possible-null-dereference
 @opindex Wno-analyzer-possible-null-dereference
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-possible-null-dereference} to disable it.
 
 This diagnostic warns for paths through the code in which a
@@ -6507,7 +6507,7 @@ possibly-NULL value is dereferenced.
 @item -Wno-analyzer-null-argument
 @opindex Wanalyzer-null-argument
 @opindex Wno-analyzer-null-argument
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-null-argument} to disable it.
 
 This diagnostic warns for paths through the code in which a
@@ -6518,7 +6518,7 @@ value.
 @item -Wno-analyzer-null-dereference
 @opindex Wanalyzer-null-dereference
 @opindex Wno-analyzer-null-dereference
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-null-dereference} to disable it.
 
 This diagnostic warns for paths through the code in which a
@@ -6527,7 +6527,7 @@ value known to be NULL is dereferenced.
 @item -Wno-analyzer-stale-setjmp-buffer
 @opindex Wanalyzer-stale-setjmp-buffer
 @opindex Wno-analyzer-stale-setjmp-buffer
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-stale-setjmp-buffer} to disable it.
 
 This diagnostic warns for paths through the code in which
@@ -6543,7 +6543,7 @@ no longer exists, and likely lead to a crash (or worse).
 @item -Wno-analyzer-tainted-array-index
 @opindex Wanalyzer-tainted-array-index
 @opindex Wno-analyzer-tainted-array-index
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-tainted-array-index} to disable it.
 
 This diagnostic warns for paths through the code in which a value
@@ -6553,7 +6553,7 @@ of an array access without being sanitized.
 @item -Wno-analyzer-use-after-free
 @opindex Wanalyzer-use-after-free
 @opindex Wno-analyzer-use-after-free
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-use-after-free} to disable it.
 
 This diagnostic warns for paths through the code in which a
@@ -6562,7 +6562,7 @@ pointer is used after @code{free} is called on it.
 @item -Wno-analyzer-use-of-pointer-in-stale-stack-frame
 @opindex Wanalyzer-use-of-pointer-in-stale-stack-frame
 @opindex Wno-analyzer-use-of-pointer-in-stale-stack-frame
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-use-of-pointer-in-stale-stack-frame}
 to disable it.
 
@@ -6572,7 +6572,7 @@ is dereferenced that points to a variable in a stale stack frame.
 @item -Wno-analyzer-use-of-uninitialized-value
 @opindex Wanalyzer-use-of-uninitialized-value
 @opindex Wno-analyzer-use-of-uninitialized-value
-This warning requires @option{--analyzer}, which enables it; use
+This warning requires @option{-fanalyzer}, which enables it; use
 @option{-Wno-analyzer-use-of-uninitialized-value} to disable it.
 
 This diagnostic warns for paths through the code in which an uninitialized
@@ -8238,7 +8238,7 @@ OpenMP construct.
 @section Options That Control Static Analysis
 
 @table @gcctabopt
-@item --analyzer
+@item -fanalyzer
 @opindex analyzer
 This option enables an static analysis of program flow which looks
 for ``interesting'' interprocedural paths through the
@@ -8271,7 +8271,7 @@ support enabled.
 @item -Wanalyzer-too-complex
 @opindex Wanalyzer-too-complex
 @opindex Wno-analyzer-too-complex
-If @option{--analyzer} is enabled, the analyzer uses various heuristics
+If @option{-fanalyzer} is enabled, the analyzer uses various heuristics
 to attempt to explore the control flow and data flow in the program,
 but these can be defeated by sufficiently complicated code.
 
diff --git a/gcc/gcc.c b/gcc/gcc.c
index a2d17e6..232cedd 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4289,7 +4289,7 @@ driver_handle_option (struct gcc_options *opts,
       handle_foffload_option (arg);
       break;
 
-    case OPT__analyzer:
+    case OPT_fanalyzer:
       {
 	validated = true;
 #ifdef ENABLE_ANALYZER
@@ -4297,8 +4297,9 @@ driver_handle_option (struct gcc_options *opts,
 #else
 	sorry ("%qs was not enabled in this build of GCC"
 	       " (missing configure-time option %qs)",
-	       "--analyzer", "--enable-plugins=analyzer");
+	       "-fanalyzer", "--enable-plugins=analyzer");
 #endif
+	do_save = false;
       }
       break;
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
index a830cf7..ac9c495 100644
--- a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
+++ b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
@@ -30,7 +30,7 @@ if [info exists DEFAULT_CFLAGS] then {
 }
 
 # If a testcase doesn't have special options, use these.
-set DEFAULT_CFLAGS "--analyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries"
+set DEFAULT_CFLAGS "-fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries"
 
 # Initialize `dg'.
 dg-init
diff --git a/gcc/testsuite/gcc.dg/analyzer/disabling.c b/gcc/testsuite/gcc.dg/analyzer/disabling.c
new file mode 100644
index 0000000..a696d1e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/disabling.c
@@ -0,0 +1,10 @@
+/* Verify that we can override -fanalyzer with -fno-analyzer.  */
+/* { dg-additional-options "-fno-analyzer" } */
+
+#include <stdlib.h>
+
+void test (void *ptr)
+{
+  free (ptr);
+  free (ptr); /* { dg-bogus "free" } */
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-dce.c b/gcc/testsuite/gcc.dg/analyzer/malloc-dce.c
index 1f61b4b..e999e43 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-dce.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-dce.c
@@ -1,4 +1,4 @@
-/* { dg-options "--analyzer -O2" } */
+/* { dg-options "-fanalyzer -O2" } */
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-double-free.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-double-free.c
index a63e7e8..5b1ba59 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-double-free.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-double-free.c
@@ -1,6 +1,6 @@
 /* Example of a multilevel wrapper around malloc/free, with a double-'free'.  */
 
-/* { dg-options "--analyzer -fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fanalyzer-checker=malloc -fanalyzer-verbose-state-changes -fdiagnostics-show-caret" } */
+/* { dg-options "-fanalyzer -fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fanalyzer-checker=malloc -fanalyzer-verbose-state-changes -fdiagnostics-show-caret" } */
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c
index a3a3909..925a266 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c
@@ -1,6 +1,6 @@
 /* Example of a multilevel wrapper around malloc, with an unchecked write.  */
 
-/* { dg-options "--analyzer -fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fdiagnostics-path-format=inline-events -fanalyzer-checker=malloc -fdiagnostics-show-caret -fanalyzer-verbose-state-changes" } */
+/* { dg-options "-fanalyzer -fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fdiagnostics-path-format=inline-events -fanalyzer-checker=malloc -fdiagnostics-show-caret -fanalyzer-verbose-state-changes" } */
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-9.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-9.c
index 03bcbdb..87e6e28 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-9.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-9.c
@@ -1,4 +1,4 @@
-/* { dg-options "--analyzer -fdiagnostics-path-format=none -fanalyzer-verbosity=1" } */
+/* { dg-options "-fanalyzer -fdiagnostics-path-format=none -fanalyzer-verbosity=1" } */
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c b/gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c
index a34b97b..6bb7a0b 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c
@@ -1,6 +1,6 @@
 /* Test path-printing in the face of macros.  */
 
-/* { dg-options "--analyzer -fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
+/* { dg-options "-fanalyzer -fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
 
 #include "malloc-macro.h"
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c b/gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c
index 9c7e933..3f2ab6f 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c
@@ -1,6 +1,6 @@
 /* Test path-printing in the face of macros.  */
 
-/* { dg-options "--analyzer -fdiagnostics-path-format=separate-events" } */
+/* { dg-options "-fanalyzer -fdiagnostics-path-format=separate-events" } */
 
 #include "malloc-macro.h"
 
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 2ac2f08..f9c392c 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -8457,7 +8457,7 @@ proc check_effective_target_lto_incremental { } {
 proc check_effective_target_analyzer { } {
     return [check_no_compiler_messages analyzer object {
 	void foo (void) { }
-    } "--analyzer"]
+    } "-fanalyzer"]
 }
 
 # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
-- 
1.8.5.3

