re PR c/8083 (GCC does not warn for aliasing violations)
PR c/8083 * c-typeck.c (build_c_cast): Warn about type punning which breaks type based aliasing. testsuite: * gcc.dg/alias-1.c: New test. From-SVN: r57698
This commit is contained in:
parent
0645ba8f0b
commit
73a7376815
|
@ -1,3 +1,9 @@
|
|||
2002-10-01 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR c/8083
|
||||
* c-typeck.c (build_c_cast): Warn about type punning which breaks
|
||||
type based aliasing.
|
||||
|
||||
2002-10-01 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* stor-layout.c (update_alignment_for_field): New function.
|
||||
|
@ -6,6 +12,7 @@
|
|||
|
||||
2002-10-01 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR other/8077
|
||||
* gcc.c (cc1_options): Add space on -auxbase-strip.
|
||||
|
||||
2002-10-01 Jim Wilson <wilson@redhat.com>
|
||||
|
|
|
@ -3759,6 +3759,23 @@ build_c_cast (type, expr)
|
|||
&& !TREE_CONSTANT (value))
|
||||
warning ("cast to pointer from integer of different size");
|
||||
|
||||
if (TREE_CODE (type) == POINTER_TYPE
|
||||
&& TREE_CODE (otype) == POINTER_TYPE
|
||||
&& TREE_CODE (expr) == ADDR_EXPR
|
||||
&& DECL_P (TREE_OPERAND (expr, 0))
|
||||
&& flag_strict_aliasing && extra_warnings
|
||||
&& !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");
|
||||
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");
|
||||
}
|
||||
|
||||
ovalue = value;
|
||||
value = convert (type, value);
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2002-10-01 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* gcc.dg/alias-1.c: New test.
|
||||
|
||||
2002-10-01 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* gcc.dg/empty1.C: New test.
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// { dg-do compile }
|
||||
// { dg-options "-W -fstrict-aliasing" }
|
||||
|
||||
// Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
// Contributed by Nathan Sidwell 29 Sep 2002 <nathan@codesourcery.com>
|
||||
|
||||
// 8083. warn about odd casts
|
||||
|
||||
typedef int YYSTYPE;
|
||||
typedef struct tDefEntry
|
||||
{
|
||||
unsigned t;
|
||||
|
||||
} tDefEntry;
|
||||
struct incomplete;
|
||||
|
||||
|
||||
YYSTYPE
|
||||
addSibMacro(
|
||||
YYSTYPE list )
|
||||
{
|
||||
tDefEntry** ppT = (tDefEntry**)&list; // { dg-warning "type punning cast" "" }
|
||||
|
||||
struct incomplete *p = (struct incomplete *)&list; // { dg-warning "type punning to incomplete" "" }
|
||||
|
||||
return list;
|
||||
}
|
||||
|
Loading…
Reference in New Issue