c-common.c (strict_aliasing_warning): Handle all component-ref like accesses.
authorRichard Guenther <rguenther@suse.de>
Mon, 28 Nov 2005 10:00:55 +0000 (10:00 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 28 Nov 2005 10:00:55 +0000 (10:00 +0000)
2005-11-28  Richard Guenther  <rguenther@suse.de>

* c-common.c (strict_aliasing_warning): Handle all
component-ref like accesses.

* gcc.dg/alias-9.c: New testcase.
* g++.dg/warn/Wstrict-aliasing-7.C: Likewise.

From-SVN: r107598

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/alias-9.c [new file with mode: 0644]

index 52b1880eb0da99d0b119f52e19985e341c6588d7..a1b40fdf81ee4224258b6dbce664dac7266cc12d 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-28  Richard Guenther  <rguenther@suse.de>
+
+       * c-common.c (strict_aliasing_warning): Handle all
+       component-ref like accesses.
+
 2005-11-28  Roger Sayle  <roger@eyesopen.com>
            Uros Bizjak  <uros@kss-loka.si>
 
index 82fe6131c1de462caf9c5ff90e57cd404f1fa266..b416a5d3648a81414dcd9d25bcfa1f7cc7737b8c 100644 (file)
@@ -966,7 +966,7 @@ strict_aliasing_warning(tree otype, tree type, tree expr)
       && POINTER_TYPE_P (type) && POINTER_TYPE_P (otype)
       && TREE_CODE (expr) == ADDR_EXPR
       && (DECL_P (TREE_OPERAND (expr, 0))
-          || TREE_CODE (TREE_OPERAND (expr, 0)) == COMPONENT_REF)
+          || handled_component_p (TREE_OPERAND (expr, 0)))
       && !VOID_TYPE_P (TREE_TYPE (type)))
     {
       /* Casting the address of an object to non void pointer. Warn
index 75ca6e4214c3347739f44e37124d7edaa451af30..7b1a543631633eea3f912279ecb83d92a440bd6f 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-28  Richard Guenther  <rguenther@suse.de>
+
+       * gcc.dg/alias-9.c: New testcase.
+       * g++.dg/warn/Wstrict-aliasing-7.C: Likewise.
+
 2005-11-28  Roger Sayle  <roger@eyesopen.com>
            Uros Bizjak  <uros@kss-loka.si>
 
diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C
new file mode 100644 (file)
index 0000000..5e41808
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wstrict-aliasing -O2" } */
+
+int a[2];
+
+double *foo1(void)
+{
+  return (double *)a; /* { dg-warning "strict-aliasing" } */
+}
+
+double *foo2(void)
+{
+  return (double *)&a[0]; /* { dg-warning "strict-aliasing" } */
+}
+
+__complex__ double x;
+int *bar(void)
+{
+  return (int *)&__imag__ x; /* { dg-warning "strict-aliasing" } */
+}
diff --git a/gcc/testsuite/gcc.dg/alias-9.c b/gcc/testsuite/gcc.dg/alias-9.c
new file mode 100644 (file)
index 0000000..6e9d4a8
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wstrict-aliasing -O2" } */
+
+int a[2];
+
+double *foo1(void)
+{
+  return (double *)a; /* { dg-warning "strict-aliasing" } */
+}
+
+double *foo2(void)
+{
+  return (double *)&a[0]; /* { dg-warning "strict-aliasing" } */
+}
+
+_Complex x;
+int *bar(void)
+{
+  return (int *)&__imag x; /* { dg-warning "strict-aliasing" } */
+}