diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2005-06-09 11:36:12 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@codesourcery.com> | 2005-06-09 11:36:12 +0000 |
commit | 4cf08d2899e1960fb15e36be68ae4852f072e8e3 (patch) | |
tree | 787ca8df932d5209b49a6b6917d989cc4a5c0b20 /gcc/c-typeck.c | |
parent | eec93d3438943b51641a432bd65a0ac0aa6a5053 (diff) |
/:
* c-typeck.c (build_c_cast): Check type punning on COMPONENT_REF
too.
testsuite:
* gcc.dg/alias-8.c: New.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@100799 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r-- | gcc/c-typeck.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index a1c7e56f76b..9429b73172c 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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"); |