OSDN Git Service

New option -Wstrict-aliasing=2.
authorwilson <wilson@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 10 Mar 2004 06:02:55 +0000 (06:02 +0000)
committerwilson <wilson@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 10 Mar 2004 06:02:55 +0000 (06:02 +0000)
* alias.c (alias_sets_might_conflict_p): New.
* c-typeck.c (build_c_cast): Call it if warn_strict_aliasing > 1.
* common.opt (Wstrict-aliasing=): New.
* flags.h (warn_strict_aliasing): Change type to int.
* opts.c (warn_strict_aliasing): Change type to int.
(common_handle_option): Handle OPT_Wstrict_aliasing_.
* tree.h (alias_sets_might_conflict_p): Declare it.
* doc/invoke.tex (-Wstrict-aliasing=2): Document it.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@79222 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/alias.c
gcc/c-typeck.c
gcc/common.opt
gcc/doc/invoke.texi
gcc/flags.h
gcc/opts.c
gcc/tree.h

index e6a791c..6016aaa 100644 (file)
@@ -1,3 +1,14 @@
+2004-03-09  James E Wilson  <wilson@specifixinc.com>
+
+       * alias.c (alias_sets_might_conflict_p): New.
+       * c-typeck.c (build_c_cast): Call it if warn_strict_aliasing > 1.
+       * common.opt (Wstrict-aliasing=): New.
+       * flags.h (warn_strict_aliasing): Change type to int.
+       * opts.c (warn_strict_aliasing): Change type to int.
+       (common_handle_option): Handle OPT_Wstrict_aliasing_.
+       * tree.h (alias_sets_might_conflict_p): Declare it.
+       * doc/invoke.tex (-Wstrict-aliasing=2): Document it.
+
 2004-03-10  Roman Zippel  <zippel@linux-m68k.org>
 
        PR bootstrap/12371
 2004-03-10  Roman Zippel  <zippel@linux-m68k.org>
 
        PR bootstrap/12371
index d670a7d..30013ec 100644 (file)
@@ -290,6 +290,19 @@ alias_sets_conflict_p (HOST_WIDE_INT set1, HOST_WIDE_INT set2)
      child of the other.  Therefore, they cannot alias.  */
   return 0;
 }
      child of the other.  Therefore, they cannot alias.  */
   return 0;
 }
+
+/* Return 1 if the two specified alias sets might conflict, or if any subtype
+   of these alias sets might conflict.  */
+
+int
+alias_sets_might_conflict_p (HOST_WIDE_INT set1, HOST_WIDE_INT set2)
+{
+  if (set1 == 0 || set2 == 0 || set1 == set2)
+    return 1;
+
+  return 0;
+}
+
 \f
 /* Return 1 if TYPE is a RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE and has
    has any readonly fields.  If any of the fields have types that
 \f
 /* Return 1 if TYPE is a RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE and has
    has any readonly fields.  If any of the fields have types that
index a49b5ea..f23fac7 100644 (file)
@@ -3027,10 +3027,17 @@ build_c_cast (tree type, tree expr)
             if the cast breaks type based aliasing.  */
          if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
            warning ("type-punning to incomplete type might break strict-aliasing rules");
             if the cast breaks type based aliasing.  */
          if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
            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 ("dereferencing type-punned pointer will break strict-aliasing rules");
+         else
+           {
+             HOST_WIDE_INT set1 = get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
+             HOST_WIDE_INT set2 = get_alias_set (TREE_TYPE (type));
+
+             if (!alias_sets_conflict_p (set1, set2))
+               warning ("dereferencing type-punned pointer will break strict-aliasing rules");
+             else if (warn_strict_aliasing > 1
+                      && !alias_sets_might_conflict_p (set1, set2))
+               warning ("dereferencing type-punned pointer might break strict-aliasing rules");
+           }
        }
 
       /* If pedantic, warn for conversions between function and object
        }
 
       /* If pedantic, warn for conversions between function and object
index d9faa60..f1a0453 100644 (file)
@@ -104,6 +104,10 @@ Wstrict-aliasing
 Common
 Warn about code which might break strict aliasing rules
 
 Common
 Warn about code which might break strict aliasing rules
 
+Wstrict-aliasing=
+Common Joined UInteger
+Warn about code which might break strict aliasing rules
+
 Wswitch
 Common
 Warn about enumerated switches, with no default, missing a case
 Wswitch
 Common
 Warn about enumerated switches, with no default, missing a case
index 8caed2b..0c9f183 100644 (file)
@@ -226,7 +226,7 @@ in the following sections.
 -Wno-multichar  -Wnonnull  -Wpacked  -Wpadded @gol
 -Wparentheses  -Wpointer-arith  -Wredundant-decls @gol
 -Wreturn-type  -Wsequence-point  -Wshadow @gol
 -Wno-multichar  -Wnonnull  -Wpacked  -Wpadded @gol
 -Wparentheses  -Wpointer-arith  -Wredundant-decls @gol
 -Wreturn-type  -Wsequence-point  -Wshadow @gol
--Wsign-compare  -Wstrict-aliasing @gol
+-Wsign-compare  -Wstrict-aliasing -Wstrict-aliasing=2 @gol
 -Wswitch  -Wswitch-default  -Wswitch-enum @gol
 -Wsystem-headers  -Wtrigraphs  -Wundef  -Wuninitialized @gol
 -Wunknown-pragmas  -Wunreachable-code @gol
 -Wswitch  -Wswitch-default  -Wswitch-enum @gol
 -Wsystem-headers  -Wtrigraphs  -Wundef  -Wuninitialized @gol
 -Wunknown-pragmas  -Wunreachable-code @gol
@@ -2449,6 +2449,13 @@ 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}.
 
 cases, but does attempt to catch the more common pitfalls. It is
 included in @option{-Wall}.
 
+@item -Wstrict-aliasing=2
+@opindex Wstrict-aliasing=2
+This option is only active when @option{-fstrict-aliasing} is active.
+It warns about all code which might break the strict aliasing rules that the
+compiler is using for optimization.  This warning catches all cases, but
+it will also give a warning for some ambiguous cases that are safe.
+
 @item -Wall
 @opindex Wall
 All of the above @samp{-W} options combined.  This enables all the
 @item -Wall
 @opindex Wall
 All of the above @samp{-W} options combined.  This enables all the
index b088f6c..8a70fc3 100644 (file)
@@ -184,7 +184,7 @@ extern bool warn_deprecated_decl;
 /* Nonzero means warn about constructs which might not be strict
    aliasing safe.  */
 
 /* Nonzero means warn about constructs which might not be strict
    aliasing safe.  */
 
-extern bool warn_strict_aliasing;
+extern int warn_strict_aliasing;
 
 /* Nonzero if generating code to do profiling.  */
 
 
 /* Nonzero if generating code to do profiling.  */
 
index fa1971c..99d576a 100644 (file)
@@ -100,7 +100,7 @@ bool warn_shadow;
 
 /* Nonzero means warn about constructs which might not be
    strict-aliasing safe.  */
 
 /* Nonzero means warn about constructs which might not be
    strict-aliasing safe.  */
-bool warn_strict_aliasing;
+int warn_strict_aliasing;
 
 /* True to warn if a switch on an enum, that does not have a default
    case, fails to have a case for every enum value.  */
 
 /* True to warn if a switch on an enum, that does not have a default
    case, fails to have a case for every enum value.  */
@@ -747,6 +747,7 @@ common_handle_option (size_t scode, const char *arg,
       break;
 
     case OPT_Wstrict_aliasing:
       break;
 
     case OPT_Wstrict_aliasing:
+    case OPT_Wstrict_aliasing_:
       warn_strict_aliasing = value;
       break;
 
       warn_strict_aliasing = value;
       break;
 
index 0a1e3fb..6af6c66 100644 (file)
@@ -2887,6 +2887,7 @@ extern tree strip_float_extensions (tree);
 extern void record_component_aliases (tree);
 extern HOST_WIDE_INT get_alias_set (tree);
 extern int alias_sets_conflict_p (HOST_WIDE_INT, HOST_WIDE_INT);
 extern void record_component_aliases (tree);
 extern HOST_WIDE_INT get_alias_set (tree);
 extern int alias_sets_conflict_p (HOST_WIDE_INT, HOST_WIDE_INT);
+extern int alias_sets_might_conflict_p (HOST_WIDE_INT, HOST_WIDE_INT);
 extern int readonly_fields_p (tree);
 extern int objects_must_conflict_p (tree, tree);
 
 extern int readonly_fields_p (tree);
 extern int objects_must_conflict_p (tree, tree);