aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2009-10-23 13:18:42 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2009-10-23 13:18:42 +0100
commitcb9c2485b2487ee5aa9a3e1b75385c508d28519f (patch)
tree0fe23e5ff51a04afd7bc7b9f279e3b3b20be309d /gcc/c-common.c
parent93f28ca73fbb038d98a74a464d04c734743720c4 (diff)
downloadgcc-cb9c2485b2487ee5aa9a3e1b75385c508d28519f.zip
gcc-cb9c2485b2487ee5aa9a3e1b75385c508d28519f.tar.gz
gcc-cb9c2485b2487ee5aa9a3e1b75385c508d28519f.tar.bz2
re PR c/41673 (variable-length array dereference inside sizeof gives "warning: dereferencing type-punned pointer will break strict-aliasing rules")
PR c/41673 * alias.c (get_alias_set): Call langhook before returning 0 for types with structural equality. * c-common.c (c_common_get_alias_set): Use alias set of element type for arrays with structural comparison. testsuite: * gcc.dg/Wstrict-aliasing-bogus-vla-1.c: New test. From-SVN: r153496
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 16e17b3..8a6d15b 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -4183,6 +4183,15 @@ c_common_get_alias_set (tree t)
tree u;
PTR *slot;
+ /* For VLAs, use the alias set of the element type rather than the
+ default of alias set 0 for types compared structurally. */
+ if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t))
+ {
+ if (TREE_CODE (t) == ARRAY_TYPE)
+ return get_alias_set (TREE_TYPE (t));
+ return -1;
+ }
+
/* Permit type-punning when accessing a union, provided the access
is directly through the union. For example, this code does not
permit taking the address of a union member and then storing