re PR c/79677 (Weird handling of -Werror=)
authorJakub Jelinek <jakub@redhat.com>
Fri, 24 Feb 2017 23:15:56 +0000 (00:15 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 24 Feb 2017 23:15:56 +0000 (00:15 +0100)
PR c/79677
* opts.h (handle_generated_option): Add GENERATED_P argument.
* opts-common.c (handle_option): Adjust function comment.
(handle_generated_option): Add GENERATED_P argument, pass it to
handle_option.
(control_warning_option): Pass false to handle_generated_option
GENERATED_P.
* opts.c (maybe_default_option): Pass true to handle_generated_option
GENERATED_P.
* optc-gen.awk: Likewise.
ada/
* gcc-interface/misc.c (gnat_handle_option): Pass true to
handle_generated_option GENERATED_P.
testsuite/
* gcc.dg/pr79677.c: New test.

From-SVN: r245728

gcc/ChangeLog
gcc/ada/ChangeLog
gcc/ada/gcc-interface/misc.c
gcc/optc-gen.awk
gcc/opts-common.c
gcc/opts.c
gcc/opts.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr79677.c [new file with mode: 0644]

index cf24e79f263a6a19cfe358ee18b87aec05d1c784..5f0ee4f2816c71578a6acdbb27cc7240b4507378 100644 (file)
@@ -1,3 +1,16 @@
+2017-02-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/79677
+       * opts.h (handle_generated_option): Add GENERATED_P argument.
+       * opts-common.c (handle_option): Adjust function comment.
+       (handle_generated_option): Add GENERATED_P argument, pass it to
+       handle_option.
+       (control_warning_option): Pass false to handle_generated_option
+       GENERATED_P.
+       * opts.c (maybe_default_option): Pass true to handle_generated_option
+       GENERATED_P.
+       * optc-gen.awk: Likewise.
+
 2017-02-24  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * config/sh/sh.md (tstsi_t): If operands[0] is a SUBREG instead of
index e4ce4d52e0f900222d86ac18a79d7c6b8b823044..079769db942728f2d1eef67c2e91e3978454af99 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/79677
+       * gcc-interface/misc.c (gnat_handle_option): Pass true to
+       handle_generated_option GENERATED_P.
+
 2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/decl.c (gnat_to_gnu_field): Do not remove the wrapper
index cdabfec09d41258467c8d64554043d85a390ea7f..1b6b3eb265acb162c82bbe69f0cfec40799adb8a 100644 (file)
@@ -149,7 +149,7 @@ gnat_handle_option (size_t scode, const char *arg, int value, int kind,
       handle_generated_option (&global_options, &global_options_set,
                               OPT_Wunused, NULL, value,
                               gnat_option_lang_mask (), kind, loc,
-                              handlers, global_dc);
+                              handlers, true, global_dc);
       warn_uninitialized = value;
       warn_maybe_uninitialized = value;
       break;
index cb3214a711cd9ac89e3e51c606cae49b5d505a31..3b9126ccf97d75f795b4279385596081b6a296b6 100644 (file)
@@ -444,7 +444,7 @@ for (i = 0; i < n_enabledby; i++) {
             print "      if (" condition ")"
             print "        handle_generated_option (opts, opts_set,"
             print "                                 " opt_enum(thisenable[j]) ", NULL, " value ","
-            print "                                 lang_mask, kind, loc, handlers, dc);"
+            print "                                 lang_mask, kind, loc, handlers, true, dc);"
         } else {
             print "#error " thisenable[j] " does not have a Var() flag"
         }
@@ -497,7 +497,7 @@ for (i = 0; i < n_langs; i++) {
                 print "      if (!opts_set->x_" opt_var_name ")"
                 print "        handle_generated_option (opts, opts_set,"
                 print "                                 " opt_enum(thisenable_opt) ", NULL, " value ","
-                print "                                 lang_mask, kind, loc, handlers, dc);"
+                print "                                 lang_mask, kind, loc, handlers, true, dc);"
             } else {
                 print "#error " thisenable_opt " does not have a Var() flag"
             }
index 8b924c9e1d73befc00bc26614be6108c62eec262..f2f7385a4c7ac6c149256aa0c943b6399a2a3a8a 100644 (file)
@@ -959,9 +959,10 @@ keep:
    option for options from the source file, UNKNOWN_LOCATION
    otherwise.  GENERATED_P is true for an option generated as part of
    processing another option or otherwise generated internally, false
-   for one explicitly passed by the user.  Returns false if the switch
-   was invalid.  DC is the diagnostic context for options affecting
-   diagnostics state, or NULL.  */
+   for one explicitly passed by the user.  control_warning_option
+   generated options are considered explicitly passed by the user.
+   Returns false if the switch was invalid.  DC is the diagnostic
+   context for options affecting diagnostics state, or NULL.  */
 
 static bool
 handle_option (struct gcc_options *opts,
@@ -1005,13 +1006,13 @@ handle_generated_option (struct gcc_options *opts,
                         size_t opt_index, const char *arg, int value,
                         unsigned int lang_mask, int kind, location_t loc,
                         const struct cl_option_handlers *handlers,
-                        diagnostic_context *dc)
+                        bool generated_p, diagnostic_context *dc)
 {
   struct cl_decoded_option decoded;
 
   generate_option (opt_index, arg, value, lang_mask, &decoded);
   return handle_option (opts, opts_set, &decoded, lang_mask, kind, loc,
-                       handlers, true, dc);
+                       handlers, generated_p, dc);
 }
 
 /* Fill in *DECODED with an option described by OPT_INDEX, ARG and
@@ -1503,7 +1504,7 @@ control_warning_option (unsigned int opt_index, int kind, const char *arg,
 
          handle_generated_option (opts, opts_set,
                                   opt_index, arg, value, lang_mask,
-                                  kind, loc, handlers, dc);
+                                  kind, loc, handlers, false, dc);
        }
     }
 }
index b38e9b4f3a7d6d4d52628e07e8ee4e7ad9e3d3ac..c4768603ec9eba08586e1e7a9c299c95652ea608 100644 (file)
@@ -403,13 +403,13 @@ maybe_default_option (struct gcc_options *opts,
     handle_generated_option (opts, opts_set, default_opt->opt_index,
                             default_opt->arg, default_opt->value,
                             lang_mask, DK_UNSPECIFIED, loc,
-                            handlers, dc);
+                            handlers, true, dc);
   else if (default_opt->arg == NULL
           && !option->cl_reject_negative)
     handle_generated_option (opts, opts_set, default_opt->opt_index,
                             default_opt->arg, !default_opt->value,
                             lang_mask, DK_UNSPECIFIED, loc,
-                            handlers, dc);
+                            handlers, true, dc);
 }
 
 /* As indicated by the optimization level LEVEL (-Os if SIZE is set,
index 56ba9101c64eaf77621bba151a1951e7df1aea9a..eb626aa90ec8e91766d1e8bcc3c5c63837c8163a 100644 (file)
@@ -353,7 +353,7 @@ bool handle_generated_option (struct gcc_options *opts,
                              size_t opt_index, const char *arg, int value,
                              unsigned int lang_mask, int kind, location_t loc,
                              const struct cl_option_handlers *handlers,
-                             diagnostic_context *dc);
+                             bool generated_p, diagnostic_context *dc);
 void generate_option (size_t opt_index, const char *arg, int value,
                      unsigned int lang_mask,
                      struct cl_decoded_option *decoded);
index ce7a3d480583f4a824f08a7309e0b6cb1025a414..651eb79a2377f775d3916bbed475a18aacaabfd7 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/79677
+       * gcc.dg/pr79677.c: New test.
+
 2017-02-24  Matthew Fortune  <matthew.fortune@imgtec.com>
 
        * gcc.target/mips/mips-ps-type-2.c (move): Force generation
diff --git a/gcc/testsuite/gcc.dg/pr79677.c b/gcc/testsuite/gcc.dg/pr79677.c
new file mode 100644 (file)
index 0000000..53a3176
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR c/79677 */
+/* { dg-do compile } */
+/* { dg-options "-Wformat -Werror=format-security -Wformat" } */
+/* { dg-message "some warnings being treated as errors" "" { target *-*-* } 0 } */
+
+void foo (char *);
+
+int
+main ()
+{
+  char s[10] = "%s";
+  foo (s);
+  __builtin_printf (s);        /* { dg-error "format not a string literal and no format arguments" } */
+  return 0;
+}