c-opts.c (c_common_decode_option): Add warn_strict_aliasing to -Wall.
authorNathan Sidwell <nathan@codesourcery.com>
Tue, 8 Oct 2002 19:20:18 +0000 (19:20 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 8 Oct 2002 19:20:18 +0000 (19:20 +0000)
gcc:
* c-opts.c (c_common_decode_option): Add warn_strict_aliasing to
-Wall.
* c-typeck.c (build_c_cast): Use warn_strict_aliasing, tweak
message.
* flags.h (warn_strict_aliasing): Declare.
* toplev.c (warn_strict_aliasing): Define.
(lang_independent_options): Add it.
* doc/invoke.texi (-Wstrict-aliasing): Document it.
testsuite:
* gcc.dg/alias-1.c: Tweak expected warning.

From-SVN: r57938

gcc/ChangeLog
gcc/c-opts.c
gcc/c-typeck.c
gcc/doc/invoke.texi
gcc/flags.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/alias-1.c
gcc/toplev.c

index 21fc42c32e8db7119481a2d019bc197e2694f929..719625767fbfb61ef8826ee974d5f6c2409b5beb 100644 (file)
@@ -1,3 +1,14 @@
+2002-10-08  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * c-opts.c (c_common_decode_option): Add warn_strict_aliasing to
+       -Wall.
+       * c-typeck.c (build_c_cast): Use warn_strict_aliasing, tweak
+       message.
+       * flags.h (warn_strict_aliasing): Declare.
+       * toplev.c (warn_strict_aliasing): Define.
+       (lang_independent_options): Add it.
+       * doc/invoke.texi (-Wstrict-aliasing): Document it.
+
 2002-10-08  Zack Weinberg  <zack@codesourcery.com>
 
        * system.h (GCCBUGURL): Delete.
index ba86e455729f21fd8550b940c5c1f3f3f60a7239..d0e8b8e3c8e5348d9c2719d1895c7693f1056321 100644 (file)
@@ -702,7 +702,8 @@ c_common_decode_option (argc, argv)
       warn_sequence_point = on;        /* Was C only.  */
       warn_sign_compare = on;  /* Was C++ only.  */
       warn_switch = on;
-
+      warn_strict_aliasing = on;
+      
       /* Only warn about unknown pragmas that are not in system
         headers.  */                                        
       warn_unknown_pragmas = on;
index 6fd14e5e74379063709ff5387fa62026f9b6448f..b5bc210dab47207f61604b2213f9152bf88ad41a 100644 (file)
@@ -3763,17 +3763,17 @@ build_c_cast (type, expr)
          && TREE_CODE (otype) == POINTER_TYPE
          && TREE_CODE (expr) == ADDR_EXPR
          && DECL_P (TREE_OPERAND (expr, 0))
-         && flag_strict_aliasing && extra_warnings
+         && flag_strict_aliasing && warn_strict_aliasing
          && !VOID_TYPE_P (TREE_TYPE (type)))
        {
          /* Casting the address of a decl to non void pointer. Warn
             if the cast breaks type based aliasing.  */
          if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
-           warning ("type punning to incomplete type might not be type based aliasing safe");
+           warning ("type-punning to incomplete type might break strict-aliasing rules");
          else if (!alias_sets_conflict_p
                   (get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0))),
                    get_alias_set (TREE_TYPE (type))))
-           warning ("type punning cast is not type based aliasing safe");
+           warning ("dereferencing type-punned pointer will break strict-aliasing rules");
        }
       
       ovalue = value;
index f112abe5d1a6f8c84b94c8f5048b40293f4133d9..51c65466d41530b88e1cace964185110e45f3ddc 100644 (file)
@@ -228,7 +228,7 @@ in the following sections.
 -Wno-import  -Wnonnull  -Wpacked  -Wpadded @gol
 -Wparentheses  -Wpointer-arith  -Wredundant-decls @gol
 -Wreturn-type  -Wsequence-point  -Wshadow @gol
--Wsign-compare  -Wswitch  -Wswitch-default -Wswitch-enum @gol
+-Wsign-compare  -Wstrict-aliasing -Wswitch  -Wswitch-default -Wswitch-enum @gol
 -Wsystem-headers -Wtrigraphs  -Wundef  -Wuninitialized @gol
 -Wunknown-pragmas  -Wunreachable-code @gol
 -Wunused  -Wunused-function  -Wunused-label  -Wunused-parameter @gol
@@ -2341,6 +2341,14 @@ GCC@.  If this command line option is used, warnings will even be issued
 for unknown pragmas in system header files.  This is not the case if
 the warnings were only enabled by the @option{-Wall} command line option.
 
+@item -Wstrict-aliasing
+@opindex Wstrict-aliasing
+This option is only active when @option{-fstrict-aliasing} is active.
+It warns about code which might break the strict aliasing rules that the
+compiler is using for optimization. The warning does not catch all
+cases, but does attempt to catch the more common pitfalls. It is
+included in @option{-Wall}.
+
 @item -Wall
 @opindex Wall
 All of the above @samp{-W} options combined.  This enables all the
index e0e7b09a1687d8fc6770ef22b658b3ad03aa2284..c5492759f07bb2a2b6df58c2e209e9f79a0b7f09 100644 (file)
@@ -184,6 +184,11 @@ extern int warn_disabled_optimization;
 
 extern int warn_deprecated_decl;
 
+/* Nonzero means warn about constructs which might not be strict
+   aliasing safe.  */
+
+extern int warn_strict_aliasing;
+
 /* Nonzero if generating code to do profiling.  */
 
 extern int profile_flag;
index e8e298b47ab531d9a790f04af51d2286ce95b649..73700051cd2f3dfd5e1e3553f1352af68fef533f 100644 (file)
@@ -1,3 +1,7 @@
+2002-10-08  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * gcc.dg/alias-1.c: Tweak expected warning.
+
 2002-10-06  D.Venkatasubramanian <dvenkat@noida.hcltech.com>
 
        * gcc.dg/20020411-1.c: Disable for 16-bit "int".
index 71056e9b6d824c64f6db2edf6b426c9999d1f9ab..a723083672cecd22d1d1c6c4b2f8f433c2f6442b 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options "-W -fstrict-aliasing" }
+// { dg-options "-Wstrict-aliasing -fstrict-aliasing" }
 
 // Copyright (C) 2002 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 29 Sep 2002 <nathan@codesourcery.com>
@@ -19,9 +19,9 @@ YYSTYPE
  addSibMacro(
          YYSTYPE  list )
  {
-     tDefEntry** ppT   = (tDefEntry**)&list; // { dg-warning "type punning cast" "" }
+     tDefEntry** ppT   = (tDefEntry**)&list; // { dg-warning "type-punned pointer" "" }
  
-     struct incomplete *p = (struct incomplete *)&list; // { dg-warning "type punning to incomplete" "" }
+     struct incomplete *p = (struct incomplete *)&list; // { dg-warning "type-punning to incomplete" "" }
      
      return list;
  }
index 1ef00cdfba18da4f4afb0cad03424ee2ff7e281a..81035b028b1a5124798934c6b868f625fc1d1372 100644 (file)
@@ -1511,6 +1511,11 @@ int warn_missing_noreturn;
 
 int warn_deprecated_decl = 1;
 
+/* Nonzero means warn about constructs which might not be
+   strict-aliasing safe.  */
+
+int warn_strict_aliasing;
+
 /* Likewise for -W.  */
 
 static const lang_independent_options W_options[] =
@@ -1556,7 +1561,9 @@ static const lang_independent_options W_options[] =
   {"deprecated-declarations", &warn_deprecated_decl, 1,
    N_("Warn about uses of __attribute__((deprecated)) declarations") },
   {"missing-noreturn", &warn_missing_noreturn, 1,
-   N_("Warn about functions which might be candidates for attribute noreturn") }
+   N_("Warn about functions which might be candidates for attribute noreturn") },
+  {"strict-aliasing", &warn_strict_aliasing, 1,
+   N_ ("Warn about code which might break the strict aliasing rules") }
 };
 
 void