From bbee4b64682d27f5ea99df3654e3e1b139443e0e Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 28 Nov 2005 10:00:55 +0000 Subject: [PATCH] c-common.c (strict_aliasing_warning): Handle all component-ref like accesses. 2005-11-28 Richard Guenther * 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 | 5 +++++ gcc/c-common.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ .../g++.dg/warn/Wstrict-aliasing-7.C | 20 +++++++++++++++++++ gcc/testsuite/gcc.dg/alias-9.c | 20 +++++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C create mode 100644 gcc/testsuite/gcc.dg/alias-9.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 52b1880eb0d..a1b40fdf81e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-11-28 Richard Guenther + + * c-common.c (strict_aliasing_warning): Handle all + component-ref like accesses. + 2005-11-28 Roger Sayle Uros Bizjak diff --git a/gcc/c-common.c b/gcc/c-common.c index 82fe6131c1d..b416a5d3648 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 75ca6e4214c..7b1a5436316 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-11-28 Richard Guenther + + * gcc.dg/alias-9.c: New testcase. + * g++.dg/warn/Wstrict-aliasing-7.C: Likewise. + 2005-11-28 Roger Sayle Uros Bizjak 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 index 00000000000..5e41808f6c4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C @@ -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 index 00000000000..6e9d4a83e35 --- /dev/null +++ b/gcc/testsuite/gcc.dg/alias-9.c @@ -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" } */ +} -- 2.30.2