re PR c/53063 (encode group options in the .opt files)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 16 Oct 2012 15:31:46 +0000 (15:31 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 16 Oct 2012 15:31:46 +0000 (15:31 +0000)
2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

PR c/53063
PR c/40989
gcc/
* optc-gen.awk: Handle new form of LangEnabledBy.
* opts.c (set_Wstrict_aliasing): Declare here. Make static.
* common.opt (Wstrict-aliasing=,Wstrict-overflow=): Do not use Init.
* doc/options.texi (LangEnabledBy): Document new form.
* flags.h (set_Wstrict_aliasing): Do not declare.
c-family/
* c.opt (Wstrict-aliasing=,Wstrict-overflow=): Use LangEnabledBy.
* c-opts.c (c_common_handle_option): Do not set them here. Add
comment.
(c_common_post_options): Likewise.
testsuite/
* gcc.dg/Wstrict-overflow-24.c: New.

From-SVN: r192502

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-opts.c
gcc/c-family/c.opt
gcc/common.opt
gcc/doc/options.texi
gcc/flags.h
gcc/optc-gen.awk
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstrict-overflow-24.c [new file with mode: 0644]

index 56a2f56e7712600c7e86ff763cf8bd4f21a55f66..8d639811a3a7c8e6d56415ce01c19ebccccab46e 100644 (file)
@@ -1,3 +1,13 @@
+2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/53063
+       PR c/40989
+       * optc-gen.awk: Handle new form of LangEnabledBy.
+       * opts.c (set_Wstrict_aliasing): Declare here. Make static.
+       * common.opt (Wstrict-aliasing=,Wstrict-overflow=): Do not use Init.
+       * doc/options.texi (LangEnabledBy): Document new form.
+       * flags.h (set_Wstrict_aliasing): Do not declare.
+
 2012-10-16  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
        * reload.c (find_reloads_subreg_address): Remove FORCE_REPLACE
index 8cc5c56a9190e6dbb4ab5fee9c86a6d2bd06741f..e2499fb8dbe5036079d04d9868f722c123511cd9 100644 (file)
@@ -1,3 +1,12 @@
+2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/53063
+       PR c/40989
+       * c.opt (Wstrict-aliasing=,Wstrict-overflow=): Use LangEnabledBy.
+       * c-opts.c (c_common_handle_option): Do not set them here. Add
+       comment.
+       (c_common_post_options): Likewise.
+
 2012-10-16  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c-ada-spec.c (ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX): Define.
index 29121b5d474ce2199a27268608fcbbd536e99419..ebbf7d91c67444af9242a018a2e37cc0a5912878 100644 (file)
@@ -360,6 +360,7 @@ c_common_handle_option (size_t scode, const char *arg, int value,
       break;
 
     case OPT_Wall:
+      /* ??? Don't add new options here. Use LangEnabledBy in c.opt.  */
       handle_generated_option (&global_options, &global_options_set,
                               OPT_Wunused, NULL, value,
                               c_family_lang_mask, kind, loc,
@@ -375,11 +376,7 @@ c_common_handle_option (size_t scode, const char *arg, int value,
       warn_sequence_point = value;     /* Was C only.  */
       warn_switch = value;
       warn_sizeof_pointer_memaccess = value;
-      if (warn_strict_aliasing == -1)
-       set_Wstrict_aliasing (&global_options, value);
       warn_address = value;
-      if (warn_strict_overflow == -1)
-       warn_strict_overflow = value;
       warn_array_bounds = value;
       warn_volatile_register_var = value;
 
@@ -939,11 +936,6 @@ c_common_post_options (const char **pfilename)
   if (warn_pointer_sign == -1)
     warn_pointer_sign = 0;
 
-  if (warn_strict_aliasing == -1)
-    warn_strict_aliasing = 0;
-  if (warn_strict_overflow == -1)
-    warn_strict_overflow = 0;
-
   /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
      It is never enabled in C++, as the minimum limit is not normative
      in that standard.  */
index b02c515327c23fd91ae7f43bdffacab9a283f262..316698468c163a3b1d973f6842062a1789ed70e2 100644 (file)
@@ -629,6 +629,14 @@ Wstrict-prototypes
 C ObjC Var(warn_strict_prototypes) Warning
 Warn about unprototyped function declarations
 
+Wstrict-aliasing=
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 3, 0)
+;
+
+Wstrict-overflow=
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0)
+;
+
 Wstrict-selector-match
 ObjC ObjC++ Var(warn_strict_selector_match) Warning
 Warn if type signatures of candidate methods do not match exactly
index 6de670b8ae536e4e886d0ff2ee97af6439ebbe65..0c6d578335afc0528f28a55e3ca02cdaff02b2d3 100644 (file)
@@ -609,7 +609,7 @@ Common Warning
 Warn about code which might break strict aliasing rules
 
 Wstrict-aliasing=
-Common Joined RejectNegative UInteger Var(warn_strict_aliasing) Init(-1) Warning
+Common Joined RejectNegative UInteger Var(warn_strict_aliasing) Warning
 Warn about code which might break strict aliasing rules
 
 Wstrict-overflow
@@ -617,7 +617,7 @@ Common Warning
 Warn about optimizations that assume that signed overflow is undefined
 
 Wstrict-overflow=
-Common Joined RejectNegative UInteger Var(warn_strict_overflow) Init(-1) Warning
+Common Joined RejectNegative UInteger Var(warn_strict_overflow) Warning
 Warn about optimizations that assume that signed overflow is undefined
 
 Wsuggest-attribute=const
index 9c004c8cd3f8fadfadc936ef77c6ba83bc816d35..8011502f9f1905b4b078800c2c3d6375b9dde116 100644 (file)
@@ -463,11 +463,15 @@ value of @option{-fmath-errno} for languages that do not use
 If not explicitly set, the option is set to the value of @option{-@var{opt}}.
 
 @item LangEnabledBy(@var{language}, @var{opt})
+@itemx LangEnabledBy(@var{language}, @var{opt}, @var{posarg}, @var{negarg})
 When compiling for the given language, the option is set to the value
-of @option{-@var{opt}}, if not explicitly set. It is possible to
-specify several different languages.  Each @var{language} must have
-been declared by an earlier @code{Language} record.  @xref{Option file
-format}.
+of @option{-@var{opt}}, if not explicitly set. In the second form, if
+@var{opt} is used in the positive form then @var{posarg} is considered
+to be passed to the option, and if @var{opt} is used in the negative
+form then @var{negarg} is considered to be passed to the option.  It
+is possible to specify several different languages.  Each
+@var{language} must have been declared by an earlier @code{Language}
+record.  @xref{Option file format}.
 
 @item NoDWARFRecord
 The option is omitted from the producer string written by
index 141185befc7fc72071e9717cf3cf9505459e0379..d56d5411e7bb34f0e46c26c0195a11921cc08989 100644 (file)
@@ -37,14 +37,6 @@ extern int base_of_path (const char *path, const char **base_out);
 extern bool fast_math_flags_set_p (const struct gcc_options *);
 extern bool fast_math_flags_struct_set_p (struct cl_optimization *);
 
-/* Used to set the level of -Wstrict-aliasing in OPTS, when no level
-   is specified.  The external way to set the default level is to use
-   -Wstrict-aliasing=level.
-   ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
-   and 0 otherwise.  After calling this function, wstrict_aliasing will be
-   set to the default value of -Wstrict_aliasing=level.  */
-
-extern void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
 \f
 /* Now the symbols that are set with `-f' switches.  */
 
index 0abe6bcf2a8e67090a210d600f3d25bdef231d34..2b168756ef523be10661de72a3844fb6f91d9616 100644 (file)
@@ -48,7 +48,7 @@ for (i = 0; i < n_opts; i++) {
                 enabledby[n_enabledby] = enabledby_name;
                 n_enabledby++;
             }
-            enables[enabledby_name] = enables[enabledby_name] opts[i] ",";
+            enables[enabledby_name] = enables[enabledby_name] opts[i] ";";
         }
     }
 
@@ -56,10 +56,20 @@ for (i = 0; i < n_opts; i++) {
     if (enabledby_arg != "") {
         n_enabledby_arg_langs = split(nth_arg(0, enabledby_arg), enabledby_arg_langs, " ");
         enabledby_name = nth_arg(1, enabledby_arg);
+        enabledby_posarg = nth_arg(2, enabledby_arg)
+       enabledby_negarg = nth_arg(3, enabledby_arg)
         enabledby_index = opt_numbers[enabledby_name];
         if (enabledby_index == "") {
-            print "#error Enabledby: " enabledby_name 
+            print "#error LangEnabledby: " enabledby_name 
         } else {
+            if (enabledby_posarg != "" && enabledby_negarg != "") {
+                with_args = "," enabledby_posarg "," enabledby_negarg
+            } else if (enabledby_posarg == "" && enabledby_negarg == "") {
+                with_args = ""
+            } else {
+                print "#error LangEnabledBy with three arguments, it should have either 2 or 4"
+            }
+
             for (j = 1; j <= n_enabledby_arg_langs; j++) {
                 lang_name = lang_sanitized_name(enabledby_arg_langs[j]);
                 lang_index = lang_numbers[enabledby_arg_langs[j]];
@@ -67,7 +77,7 @@ for (i = 0; i < n_opts; i++) {
                     enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_name;
                     n_enabledby_lang[lang_index]++;
                 }
-                enables[lang_name,enabledby_name] = enables[lang_name,enabledby_name] opts[i] ",";
+                enables[lang_name,enabledby_name] = enables[lang_name,enabledby_name] opts[i] with_args ";";
             }
         }
     }
@@ -388,7 +398,7 @@ print "    {                                                                 "
 for (i = 0; i < n_enabledby; i++) {
     enabledby_name = enabledby[i];
     print "    case " opt_enum(enabledby_name) ":"
-    n_enables = split(enables[enabledby_name], thisenable, ",");
+    n_enables = split(enables[enabledby_name], thisenable, ";");
     for (j = 1; j < n_enables; j++) {
         opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]);
         if (opt_var_name != "") {
@@ -431,16 +441,26 @@ for (i = 0; i < n_langs; i++) {
     for (k = 0; k < n_enabledby_lang[i]; k++) {
         enabledby_name = enabledby[lang_name,k];
         print "    case " opt_enum(enabledby_name) ":"
-        n_enables = split(enables[lang_name,enabledby_name], thisenable, ",");
-        for (j = 1; j < n_enables; j++) {
-            opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]);
+        n_thisenable = split(enables[lang_name,enabledby_name], thisenable, ";");
+        for (j = 1; j < n_thisenable; j++) {
+            n_thisenable_args = split(thisenable[j], thisenable_args, ",");
+            if (n_thisenable_args == 1) {
+                thisenable_opt = thisenable[j];
+                value = "value";
+            } else {
+                thisenable_opt = thisenable_args[1];
+                with_posarg = thisenable_args[2];
+                with_negarg = thisenable_args[3];
+                value = "value ? " with_posarg " : " with_negarg;
+            }
+            opt_var_name = var_name(flags[opt_numbers[thisenable_opt]]);
             if (opt_var_name != "") {
                 print "      if (!opts_set->x_" opt_var_name ")"
                 print "        handle_generated_option (opts, opts_set,"
-                print "                                 " opt_enum(thisenable[j]) ", arg, value,"
+                print "                                 " opt_enum(thisenable_opt) ", NULL, " value ","
                 print "                                 lang_mask, kind, loc, handlers, dc);"
             } else {
-                print "#error " thisenable[j] " does not have a Var() flag"
+                print "#error " thisenable_opt " does not have a Var() flag"
             }
         }
         print "      break;\n"
index ccfe3c70a914fd8a89e184812825466c46e168a5..aea0cfc839f072849e06a6301a8ef066df483199 100644 (file)
@@ -37,6 +37,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "insn-attr-common.h"
 #include "common/common-target.h"
 
+static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
+
 /* Indexed by enum debug_info_type.  */
 const char *const debug_type_names[] =
 {
@@ -1801,7 +1803,7 @@ handle_param (struct gcc_options *opts, struct gcc_options *opts_set,
    ONOFF is assumed to take value 1 when -Wstrict-aliasing is specified,
    and 0 otherwise.  After calling this function, wstrict_aliasing will be
    set to the default value of -Wstrict_aliasing=level, currently 3.  */
-void
+static void
 set_Wstrict_aliasing (struct gcc_options *opts, int onoff)
 {
   gcc_assert (onoff == 0 || onoff == 1);
index 5ebe169568cfd2b1ef101a7a3a4c52a8f3f7f434..6c6bf05ef7028b821fcd6f4f831e5f0fe5d88f83 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c/53063
+       PR c/40989
+       * gcc.dg/Wstrict-overflow-24.c: New.
+
 2012-10-16  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/50981
diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-24.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-24.c
new file mode 100644 (file)
index 0000000..05e8dd1
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fstrict-overflow -O2" } */
+/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */
+#pragma GCC diagnostic error "-Wstrict-overflow"
+
+int
+foo (int i)
+{
+  return __builtin_abs (i) >= 0; /* { dg-error "assuming signed overflow does not occur" "correct warning" } */
+}