PR driver/80545 - option -Wstringop-overflow not recognized by Fortran
authorMartin Sebor <msebor@redhat.com>
Wed, 24 Jul 2019 20:34:03 +0000 (20:34 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Wed, 24 Jul 2019 20:34:03 +0000 (14:34 -0600)
gcc/cp/ChangeLog:

PR driver/80545
* decl.c (finish_function): Use lang_mask.

gcc/testsuite/ChangeLog:

PR driver/80545
* gcc.misc-tests/help.exp: Add tests.
* lib/options.exp: Handle C++.

gcc/ChangeLog:

PR driver/80545
* diagnostic.c (diagnostic_classify_diagnostic): Use lang_mask.
(diagnostic_report_diagnostic): Same.
* diagnostic.h (diagnostic_context::option_enabled): Add an argument.
(diagnostic_context::lang_mask): New data member.
* ipa-pure-const.c (suggest_attribute): Use
lang_hooks.option_lang_mask ().
* opts-common.c (option_enabled): Handle new argument.
(get_option_state): Pass an additional argument.
* opts.c (print_filtered_help): Print supported languages for
unsupported options.  Adjust printing of current state.
* opts.h (option_enabled): Add argument.
* toplev.c (print_switch_values): Use lang_mask.
(general_init): Set global_dc->lang_mask.

From-SVN: r273771

13 files changed:
gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/diagnostic.c
gcc/diagnostic.h
gcc/ipa-pure-const.c
gcc/opts-common.c
gcc/opts.c
gcc/opts.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.misc-tests/help.exp
gcc/testsuite/lib/options.exp
gcc/toplev.c

index 7b3e03e6a43eee63987052fde0bfedd68ce9691a..5cd80e8c7a1609e17d1e3d5d683c0201e3b4f17d 100644 (file)
@@ -1,3 +1,20 @@
+2019-07-24  Martin Sebor  <msebor@redhat.com>
+
+       PR driver/80545
+       * diagnostic.c (diagnostic_classify_diagnostic): Use lang_mask.
+       (diagnostic_report_diagnostic): Same.
+       * diagnostic.h (diagnostic_context::option_enabled): Add an argument.
+       (diagnostic_context::lang_mask): New data member.
+       * ipa-pure-const.c (suggest_attribute): Use
+       lang_hooks.option_lang_mask ().
+       * opts-common.c (option_enabled): Handle new argument.
+       (get_option_state): Pass an additional argument.
+       * opts.c (print_filtered_help): Print supported languages for
+       unsupported options.  Adjust printing of current state.
+       * opts.h (option_enabled): Add argument.
+       * toplev.c (print_switch_values): Use lang_mask.
+       (general_init): Set global_dc->lang_mask.
+
 2019-07-24  Iain Sandoe  <iain@sandoe.co.uk>
 
        PR bootstrap/87030
index d645cdef147be15f212ddbc2ee0a514d4b3edb13..925b9efdfd963b28c43f60392a2f1dae9c730091 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-24  Martin Sebor  <msebor@redhat.com>
+
+       PR driver/80545
+       * decl.c (finish_function): Use lang_mask.
+
 2019-07-20  Jason Merrill  <jason@redhat.com>
 
        * cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also
index dbcf681c78376f1effa661a0af46a0343891458a..76bb58371404df07b038450e34856567ac4027af 100644 (file)
@@ -16301,6 +16301,7 @@ finish_function (bool inline_p)
              && same_type_ignoring_top_level_qualifiers_p
                  (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
              && global_dc->option_enabled (OPT_Wreturn_type,
+                                           global_dc->lang_mask,
                                            global_dc->option_state))
            add_return_star_this_fixit (&richloc, fndecl);
        }
index 4761b4349d393b663d62b8725f8de8b3a43a73e8..96b6fa300527dfde069baf1726479877d8d9f0d3 100644 (file)
@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "edit-context.h"
 #include "selftest.h"
 #include "selftest-diagnostic.h"
+#include "opts.h"
 
 #ifdef HAVE_TERMIOS_H
 # include <termios.h>
@@ -696,6 +697,7 @@ diagnostic_classify_diagnostic (diagnostic_context *context,
       if (old_kind == DK_UNSPECIFIED)
        {
          old_kind = !context->option_enabled (option_index,
+                                              context->lang_mask,
                                               context->option_state)
            ? DK_IGNORED : (context->warning_as_error_requested
                            ? DK_ERROR : DK_WARNING);
@@ -957,6 +959,7 @@ diagnostic_report_diagnostic (diagnostic_context *context,
       /* This tests if the user provided the appropriate -Wfoo or
         -Wno-foo option.  */
       if (! context->option_enabled (diagnostic->option_index,
+                                    context->lang_mask,
                                     context->option_state))
        return false;
 
index 46c3b50a5400fbbeb07565f37e6cdc5b6f7bd7ac..530acb45b386e880990d60c843d98ae42b3ca148 100644 (file)
@@ -180,7 +180,7 @@ struct diagnostic_context
 
   /* Client hook to say whether the option controlling a diagnostic is
      enabled.  Returns nonzero if enabled, zero if disabled.  */
-  int (*option_enabled) (int, void *);
+  int (*option_enabled) (int, unsigned, void *);
 
   /* Client information to pass as second argument to
      option_enabled.  */
@@ -206,6 +206,9 @@ struct diagnostic_context
 
   int lock;
 
+  /* A copy of lang_hooks.option_lang_mask ().  */
+  unsigned lang_mask;
+
   bool inhibit_notes_p;
 
   /* When printing source code, should the characters at carets and ranges
index db91d2c1a32521d54e0801558e1fae84be84d279..4b2a79f18a986cc8a158d907665879b1ecfd7bee 100644 (file)
@@ -199,7 +199,7 @@ suggest_attribute (int option, tree decl, bool known_finite,
                   hash_set<tree> *warned_about,
                   const char * attrib_name)
 {
-  if (!option_enabled (option, &global_options))
+  if (!option_enabled (option, lang_hooks.option_lang_mask (), &global_options))
     return warned_about;
   if (TREE_THIS_VOLATILE (decl)
       || (known_finite && function_always_visible_to_compiler_p (decl)))
index e3f9c549b100c1dbeabfbc869c0205ab0eb42b49..e2a315ba229f6510a1ca7e633bee1fcc95f7352f 100644 (file)
@@ -1526,9 +1526,15 @@ option_flag_var (int opt_index, struct gcc_options *opts)
    or -1 if it isn't a simple on-off switch.  */
 
 int
-option_enabled (int opt_idx, void *opts)
+option_enabled (int opt_idx, unsigned lang_mask, void *opts)
 {
   const struct cl_option *option = &(cl_options[opt_idx]);
+
+  /* A language-specific option can only be considered enabled when it's
+     valid for the current language.  */
+  if (option->flags & CL_LANG_ALL && !(option->flags | lang_mask))
+    return 0;
+
   struct gcc_options *optsg = (struct gcc_options *) opts;
   void *flag_var = option_flag_var (opt_idx, optsg);
 
@@ -1598,7 +1604,7 @@ get_option_state (struct gcc_options *opts, int option,
 
     case CLVC_BIT_CLEAR:
     case CLVC_BIT_SET:
-      state->ch = option_enabled (option, opts);
+      state->ch = option_enabled (option, -1, opts);
       state->data = &state->ch;
       state->size = 1;
       break;
index 076d0007c7e3b9bb91bd3261dae58f109cd14dcb..296f0f618027c9448a0b096091c87361aac21ded 100644 (file)
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "common/common-target.h"
 #include "spellcheck.h"
 #include "opt-suggestions.h"
+#include "diagnostic-color.h"
 
 static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
 
@@ -1460,10 +1461,37 @@ print_filtered_help (unsigned int include_flags,
          else
            strcpy (new_help, "\t");
 
+         /* Set to print whether the option is enabled or disabled,
+            or, if it's an alias for another option, the name of
+            the aliased option.  */
+         bool print_state = false;
+
          if (flag_var != NULL
              && option->var_type != CLVC_DEFER)
            {
-             if (option->flags & CL_JOINED)
+             /* If OPTION is only available for a specific subset
+                of languages other than this one, mention them.  */
+             bool avail_for_lang = true;
+             if (unsigned langset = option->flags & CL_LANG_ALL)
+               {
+                 if (!(langset & lang_mask))
+                   {
+                     avail_for_lang = false;
+                     strcat (new_help, _("[available in "));
+                     for (unsigned i = 0, n = 0; (1U << i) < CL_LANG_ALL; ++i)
+                       if (langset & (1U << i))
+                         {
+                           if (n++)
+                             strcat (new_help, ", ");
+                           strcat (new_help, lang_names[i]);
+                         }
+                     strcat (new_help, "]");
+                   }
+               }
+             if (!avail_for_lang)
+               ; /* Print nothing else if the option is not available
+                    in the current language.  */
+             else if (option->flags & CL_JOINED)
                {
                  if (option->var_type == CLVC_STRING)
                    {
@@ -1487,12 +1515,50 @@ print_filtered_help (unsigned int include_flags,
                                "%s", arg);
                    }
                  else
-                   sprintf (new_help + strlen (new_help),
-                            "%d", * (int *) flag_var);
+                   {
+                     if (option->cl_host_wide_int)
+                       sprintf (new_help + strlen (new_help),
+                                _("%llu bytes"), (unsigned long long)
+                                *(unsigned HOST_WIDE_INT *) flag_var);
+                     else
+                       sprintf (new_help + strlen (new_help),
+                                "%i", * (int *) flag_var);
+                   }
+               }
+             else
+               print_state = true;
+           }
+         else
+           /* When there is no argument, print the option state only
+              if the option takes no argument.  */
+           print_state = !(option->flags & CL_JOINED);
+
+         if (print_state)
+           {
+             if (option->alias_target < N_OPTS
+                 && option->alias_target != OPT_SPECIAL_deprecated
+                 && option->alias_target != OPT_SPECIAL_ignore
+                 && option->alias_target != OPT_SPECIAL_input_file
+                 && option->alias_target != OPT_SPECIAL_program_name
+                 && option->alias_target != OPT_SPECIAL_unknown)
+               {
+                 const struct cl_option *target
+                   = &cl_options[option->alias_target];
+                 sprintf (new_help + strlen (new_help), "%s%s",
+                          target->opt_text,
+                          option->alias_arg ? option->alias_arg : "");
                }
+             else if (option->alias_target == OPT_SPECIAL_ignore)
+               strcat (new_help, ("[ignored]"));
              else
-               strcat (new_help, option_enabled (i, opts)
-                       ? _("[enabled]") : _("[disabled]"));
+               {
+                 /* Print the state for an on/off option.  */
+                 int ena = option_enabled (i, lang_mask, opts);
+                 if (ena > 0)
+                   strcat (new_help, _("[enabled]"));
+                 else if (ena == 0)
+                   strcat (new_help, _("[disabled]"));
+               }
            }
 
          help = new_help;
index e5723a946f7b4417c4cecf4773df683783aa82ff..472232293881beb17d5771f35b416c0628ee192d 100644 (file)
@@ -359,7 +359,8 @@ extern void decode_options (struct gcc_options *opts,
                            location_t loc,
                            diagnostic_context *dc,
                            void (*target_option_override_hook) (void));
-extern int option_enabled (int opt_idx, void *opts);
+extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
+
 extern bool get_option_state (struct gcc_options *, int,
                              struct cl_option_state *);
 extern void set_option (struct gcc_options *opts,
index 621eda94bf00b73c571d25cb995ab3f9699467c4..4749b0cef36a5ce5d3d377c46bf097e64166b82f 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-24  Martin Sebor  <msebor@redhat.com>
+
+       PR driver/80545
+       * gcc.misc-tests/help.exp: Add tests.
+       * lib/options.exp: Handle C++.
+
 2019-07-24  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * gcc.target/arc/arc.exp (check_effective_target_accregs): New
index 307f1e9c3cb2dfaa7e6a264801ed02ef84be4ad4..b8a09fcd5ab6bbe85bf64522da9a33b31591fe9c 100644 (file)
@@ -91,6 +91,34 @@ maximum number of
 -O
 } "" ""
 
+# Verify that a C++/Objective C++ only option is indicated as such
+# by the C compiler.
+check_for_options c "-Q --help=warnings" {
+-Wclass-memaccess[ \t]+\[available in C\+\+, ObjC\+\+\]
+} "" ""
+
+# Do the same for a C/Objective C only option and the C++ compiler.
+check_for_options c++ "-Q --help=warnings" {
+-Wabsolute-value[ \t]+\[available in C, ObjC\]
+} "" ""
+
+# Verify that an option that's an alias for another option is shown
+# with the other option as the value.
+check_for_options c "-Q --help=warnings" {
+--all-warnings[ \t]+\-Wall
+-W[ \t]+-Wextra
+-Wmissing-format-attribute[ \t]+-Wsuggest-attribute=format
+-Wno-alloc-size-larger-than[ \t]+-Walloc-size-larger-than=[1-9][0-9]+
+-Wno-vla-larger-than[ \t]+-Wvla-larger-than=[1-9][0-9]+
+} "" ""
+
+# Verify that an option that expects a byte-size argument is shown with
+# a meaningful byte-size argument as the value.
+check_for_options c "-Q --help=warnings" {
+-Walloc-size-larger-than=[ \t]+[1-9][0-9]+ bytes
+-Wlarger-than=[^\n\r]+[1-9][0-9]+ bytes
+} "" ""
+
 # Ensure PR 37805 is fixed.
 # Specify patterns (arguments 3 and later) that match option names
 # at the beginning of the line and not when they are referenced by
index b8503078c0f634f70d295e95e68354a1517adbc6..c8f0c705e40e3526f2bceea1a947ab88e3fb2bf9 100644 (file)
@@ -34,21 +34,30 @@ proc check_for_options_with_filter { language gcc_options exclude \
                                         compiler_patterns \
                                         compiler_non_patterns \
                                         expected_failure } {
-    set filename test-[pid]
-    set fd [open $filename.c w]
-    puts $fd "int main (void) { return 0; }"
-    close $fd
-    remote_download host $filename.c
-
     set test "compiler driver $gcc_options option(s):"
     set gcc_options "\{additional_flags=$gcc_options\}"
 
     switch "$language" {
-       "c" { set compiler cc1 }
+       "c" {
+           set compiler cc1
+           set suffix c
+       }
+       "c++" {
+           set compiler cc1plus
+           set suffix cc
+       }
        default { error "unknown language" }
     }
-    set gcc_output [gcc_target_compile $filename.c $filename.x executable $gcc_options]
-    remote_file build delete $filename.c $filename.x $filename.gcno
+
+    set filebase test-[pid]
+    set srcfname $filebase.$suffix
+    set fd [open $srcfname w]
+    puts $fd "int main (void) { return 0; }"
+    close $fd
+    remote_download host $srcfname
+
+    set gcc_output [gcc_target_compile $srcfname $filebase.x executable $gcc_options]
+    remote_file build delete $srcfname $filebase.x $filebase.gcno
 
     if { $exclude != "" } {
        set lines [split $gcc_output "\n"]
index 56ef63e5adb06f01bfc4258db3faf99ef26530a6..7e0b9216dea6c3c7e18261ea36ae2bc66c52f459 100644 (file)
@@ -815,9 +815,10 @@ print_switch_values (print_switch_fn_type print_fn)
   pos = print_single_switch (print_fn, 0,
                             SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
 
+  unsigned lang_mask = lang_hooks.option_lang_mask ();
   for (j = 0; j < cl_options_count; j++)
     if (cl_options[j].cl_report
-       && option_enabled (j, &global_options) > 0)
+       && option_enabled (j, lang_mask, &global_options) > 0)
       pos = print_single_switch (print_fn, pos,
                                 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
 
@@ -1088,6 +1089,7 @@ general_init (const char *argv0, bool init_signals)
   /* Initialize the diagnostics reporting machinery, so option parsing
      can give warnings and errors.  */
   diagnostic_initialize (global_dc, N_OPTS);
+  global_dc->lang_mask = lang_hooks.option_lang_mask ();
   /* Set a default printer.  Language specific initializations will
      override it later.  */
   tree_diagnostics_defaults (global_dc);