This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Handle &ARRAY_REF etc. in strict_aliasing_warning
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 24 Nov 2005 14:44:49 +0100 (CET)
- Subject: [PATCH] Handle &ARRAY_REF etc. in strict_aliasing_warning
This makes -Wstrict-aliasing warn for casts like
int a[2];
double *p = (double *)&a[0];
which we didn't before. Still, we warned about
double *p = (double *)a;
which is really the same.
Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for mainline?
Thanks,
Richard.
:ADDPATCH:
2005-11-24 Richard Guenther <rguenther@suse.de>
* c-common.c (strict_aliasing_warning): Handle all
component-ref like accesses.
Index: c-common.c
===================================================================
*** c-common.c (revision 107459)
--- c-common.c (working copy)
*************** strict_aliasing_warning(tree otype, tree
*** 966,972 ****
&& 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)
&& !VOID_TYPE_P (TREE_TYPE (type)))
{
/* Casting the address of an object to non void pointer. Warn
--- 966,972 ----
&& POINTER_TYPE_P (type) && POINTER_TYPE_P (otype)
&& TREE_CODE (expr) == ADDR_EXPR
&& (DECL_P (TREE_OPERAND (expr, 0))
! || handled_component_p (TREE_OPERAND (expr, 0)))
&& !VOID_TYPE_P (TREE_TYPE (type)))
{
/* Casting the address of an object to non void pointer. Warn