* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@57938
138bc75d-0d04-0410-961f-
82ee72b054a4
+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.
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;
&& 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;
-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
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
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;
+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".
// { 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>
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;
}
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[] =
{"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