mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-16 09:09:41 +08:00
c-opts.c (c_common_decode_option): Add warn_strict_aliasing to -Wall.
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
This commit is contained in:
parent
b7932de6a1
commit
bf52f89914
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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".
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user