This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][RFC] Don't warn for alias-set-0 cast to incomplete struct


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" } */
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]