[analyzer] Convert from "--analyzer" to "-fanalyzer"/"-fno-analyzer"

David Malcolm dmalcolm@redhat.com
Wed Nov 27 23:35:00 GMT 2019


This patch updates the command-line option used to enable the analyzer
from "--analyzer" to "-fanalyzer" (--analyzer is still accepted, via
the map from prefix "--" to "-f" in option_map in opts-common.c)

The patch also adds support for -fno-analyzer: given uses of -fno-analyzer
and -fanalyzer, the last one used on the command line "wins".

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

Pushed to branch "dmalcolm/analyzer" on the GCC git mirror.

gcc/ChangeLog:
	* analyzer/Make-plugin.in (ANALYZER_SELFTEST_FLAGS): Replace
	"--analyzer" with "-fanalyzer".
	* common.opt (-analyzer): Replace with..
	(fanalyzer): ...this.
	* doc/invoke.texi: Replace "--analyzer" with "-fanalyzer" throughout.
	Add -fno-analyzer to index.
	* gcc.c (driver_handle_option): Handle -fanalyzer by simplying
	updating flag_analyzer, moving the injection of the plugin to:
	(process_command): ...here.

gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/analyzer.exp: Replace "--analyzer" with
	"-fanalyzer".
	* gcc.dg/analyzer/disabling.c: New test.
	* gcc.dg/analyzer/malloc-dce.c: Replace "dg-options" with
	"dg-additional-options", dropping usage of "-fanalyzer".
	* gcc.dg/analyzer/malloc-ipa-8-double-free.c: Replace "dg-options"
	with "dg-additional-options", dropping usage of "-fanalyzer".  Add
	"-fdiagnostics-path-format=inline-events".
	* gcc.dg/analyzer/malloc-ipa-8-unchecked.c: Replace "dg-options"
	with "dg-additional-options", dropping usage of "-fanalyzer".
	* gcc.dg/analyzer/malloc-ipa-9.c: Likewise.
	* gcc.dg/analyzer/malloc-macro-inline-events.c: Likewise.
	* gcc.dg/analyzer/malloc-macro-separate-events.c: Likewise.
	* lib/target-supports.exp
	(check_effective_target_lto_incremental): Replace "--analyzer"
	with "-fanalyzer".
---
 gcc/analyzer/Make-plugin.in                   |  2 +-
 gcc/common.opt                                |  6 +--
 gcc/doc/invoke.texi                           | 38 ++++++++++---------
 gcc/gcc.c                                     | 25 ++++++------
 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 +-
 .../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 +-
 .../analyzer/malloc-macro-inline-events.c     |  2 +-
 .../analyzer/malloc-macro-separate-events.c   |  2 +-
 gcc/testsuite/lib/target-supports.exp         |  2 +-
 13 files changed, 54 insertions(+), 43 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 08c96f12203e..08f58f467a2a 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 3f6de9629899..840e9f435657 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 caeb9ce30f53..286c1623aaa7 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,8 +8238,10 @@ OpenMP construct.
 @section Options That Control Static Analysis
 
 @table @gcctabopt
-@item --analyzer
+@item -fanalyzer
 @opindex analyzer
+@opindex fanalyzer
+@opindex fno-analyzer
 This option enables an static analysis of program flow which looks
 for ``interesting'' interprocedural paths through the
 code, and issues warnings for problems found on them.
@@ -8271,7 +8273,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 a2d17e672165..e8d3953f4329 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3965,6 +3965,7 @@ driver_handle_option (struct gcc_options *opts,
       add_linker_option ("--target-help", 13);
       break;
 
+    case OPT_fanalyzer:
     case OPT__no_sysroot_suffix:
     case OPT_pass_exit_codes:
     case OPT_print_search_dirs:
@@ -4289,19 +4290,6 @@ driver_handle_option (struct gcc_options *opts,
       handle_foffload_option (arg);
       break;
 
-    case OPT__analyzer:
-      {
-	validated = true;
-#ifdef ENABLE_ANALYZER
-	save_switch ("-fplugin=analyzer_plugin", 0, NULL, validated, true);
-#else
-	sorry ("%qs was not enabled in this build of GCC"
-	       " (missing configure-time option %qs)",
-	       "--analyzer", "--enable-plugins=analyzer");
-#endif
-      }
-      break;
-
     default:
       /* Various driver options need no special processing at this
 	 point, having been handled in a prescan above or being
@@ -4623,6 +4611,17 @@ process_command (unsigned int decoded_options_count,
 			   CL_DRIVER, &handlers, global_dc);
     }
 
+  if (flag_analyzer)
+    {
+#ifdef ENABLE_ANALYZER
+      save_switch ("-fplugin=analyzer_plugin", 0, NULL, true, true);
+#else
+      sorry ("%qs was not enabled in this build of GCC"
+	     " (missing configure-time option %qs)",
+	     "-fanalyzer", "--enable-plugins=analyzer");
+#endif
+    }
+
   /* If the user didn't specify any, default to all configured offload
      targets.  */
   if (ENABLE_OFFLOADING && offload_targets == NULL)
diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
index a830cf76a21f..ac9c49511aa0 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 000000000000..a696d1e021e0
--- /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 1f61b4bc4a2a..1b4b8788b86b 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-additional-options "-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 a63e7e811856..50d907f738c1 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-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fdiagnostics-path-format=inline-events -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 a3a3909f01d3..f204331f0a95 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-additional-options "-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 03bcbdb1c122..a0c78fd6c4ec 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-additional-options "-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 a34b97b72ba1..fad6d6e63744 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-additional-options "-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 9c7e933d84ae..e7483af9230e 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-additional-options "-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 59e0540ee237..5089622775ac 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -8470,7 +8470,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.
-- 
2.21.0



More information about the Gcc-patches mailing list