This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][RFC] Don't warn for alias-set-0 cast to incomplete struct
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Nov 2005 14:46:47 +0100 (CET)
- Subject: Re: [PATCH][RFC] Don't warn for alias-set-0 cast to incomplete struct
- References: <Pine.LNX.4.63.0511141432580.6049@t148.fhfr.qr>
On Mon, 14 Nov 2005, Richard Guenther wrote:
>
> This patch disables the 'type-punning to incomplete type might break
> strict-aliasing rules' in case of the pointer target being in alias set
> zero. Of course one may argue this warning is bogous anyway, as one
> can't dereference the pointer, just like void*
>
> This breaks using opaque pointers in glib, which does soemthing along
>
> struct Y;
> struct X {
> struct Y *y;
> union {
> char pad[20];
> } u;
> };
> struct X x;
>
> (struct Y*)x.u.pad
>
> Ok for mainline?
>
> Thanks,
> Richard.
>
> 2005-11-14 Richard Guenther <rguenther@suse.de>
>
> * c-typeck.c (build_c_cast): Don't warn for casting to
> pointer to incomplete type if the original alias set is
> zero.
>
> * gcc.dg/compile/Walias.c: New testcase.
Whoops, there's no gcc.dg/compile. Instead consider
* gcc.dg/Walias-1.c: New testcase.
/* { dg-options "-O2 -Wall" } */
struct Y;
struct X
{
struct Y *y;
union {
char pad[20];
int i;
} u;
};
struct X x;
struct Y *foo(void)
{
return (struct Y*)x.u.pad; /* { dg-bogus "type-punning to incomplete
type" } */
}
struct Y *bar(void)
{
return (struct Y*)&x.u.i; /* { dg-warning "type-punning to incomplete
type" } */
}