gcc-patches@gcc.gnu.org
[Top] [All Lists]

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

Subject: Re: [PATCH][RFC] Don't warn for alias-set-0 cast to incomplete struct
From: Richard Guenther
Date: Mon, 14 Nov 2005 14:46:47 +0100 CET
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@xxxxxxx>
> 
>         * 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" } */
}

<Prev in Thread] Current Thread [Next in Thread>