Commit 5878b92f by Nathan Sidwell Committed by Nathan Sidwell

c-typeck.c (build_c_cast): Check type punning on COMPONENT_REF too.

/:
	* c-typeck.c (build_c_cast): Check type punning on COMPONENT_REF
	too.
testsuite:
	* gcc.dg/alias-8.c: New.

From-SVN: r100799
parent 9df3d545
2005-06-09 Nathan Sidwell <nathan@codesourcery.com>
* c-typeck.c (build_c_cast): Check type punning on COMPONENT_REF
too.
2005-06-09 Bernd Schmidt <bernd.schmidt@analog.com>
* config/bfin/bfin.c (enum bfin_builtins): Moved here from...
......
......@@ -3304,14 +3304,15 @@ build_c_cast (tree type, tree expr)
&& !TREE_CONSTANT (value))
warning (0, "cast to pointer from integer of different size");
if (TREE_CODE (type) == POINTER_TYPE
if (flag_strict_aliasing && warn_strict_aliasing
&& TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE
&& TREE_CODE (expr) == ADDR_EXPR
&& DECL_P (TREE_OPERAND (expr, 0))
&& flag_strict_aliasing && warn_strict_aliasing
&& (DECL_P (TREE_OPERAND (expr, 0))
|| TREE_CODE (TREE_OPERAND (expr, 0)) == COMPONENT_REF)
&& !VOID_TYPE_P (TREE_TYPE (type)))
{
/* Casting the address of a decl to non void pointer. Warn
/* Casting the address of an object to non void pointer. Warn
if the cast breaks type based aliasing. */
if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
warning (0, "type-punning to incomplete type might break strict-aliasing rules");
......
2005-06-09 Nathan Sidwell <nathan@codesourcery.com>
* gcc.dg/alias-8.c: New.
2005-06-08 Joseph S. Myers <joseph@codesourcery.com>
* gcc.dg/format/cmn_err-1.c: Update.
......
// { dg-do compile }
// { dg-options "-Wstrict-aliasing=2 -fstrict-aliasing" }
struct s {
char *p;
};
void
func(struct s *ptr)
{
*(void **)&ptr->p = 0; /* { dg-warning "type-punned pointer" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment