Bug 11855

Summary: aliasing problem
Product: gcc Reporter: Fabien Douze <fabdouze>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs
Priority: P2    
Version: 3.2.2   
Target Milestone: 3.4.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Fabien Douze 2003-08-08 14:12:23 UTC
I have the following code

typedef struct _LSPESn  
{ 
    struct _LSPESn *esnext;          /* next ES neighbour in LSP chain */ 
     
    X               esdefm;          /* ES neighbour default metric    */ 
    X               esdlym;          /* ES neighbour delay metric      */ 
    X               esexpm;          /* ES neighbour expense metric    */ 
    X               eserrm;          /* ES neighbour error metric      */ 
    X               esid[LGSYSID];   /* ES neighbour system ID         */ 
} LSPESnT, *LSPESnTp; 

typedef struct STC
{
  struct STC *stnext ;
}
ST, *STp;



   LSPESnTp es2, esn; 

   for ( esn = ent->lspesn ; 0!=esn ; esn = es2 )
   {
      es2 = esn->esnext;
      (((STp)(  (STp)esn  ))->stnext)  = ( &(((SATenTp)( E2Ispp ))->sat_i2i. fr
eeLspESn )  )->prp_first; 
      ( & (((SATenTp)( E2Ispp ))->sat_i2i.reeLspESn )  )->prp_first = ((STp)( 
(STp)esn )); ;
   }

It causes an infinit loop when compiling with -O2 option. 
Apperently, gcc considere esn->esnext and (((STp)(  (STp)esn  ))->stnext) as
two different memory area and skip es2 in the generated library.

Isn't it a gcc bug?
It seems to be the same case than in bug 9902. But I do not see
which aliasing rules is not respected.

Thanks,
Fabien
Comment 1 Falk Hueffner 2003-08-08 14:41:57 UTC
There is only one:

"An object shall have its stored value accessed only by an lvalue
expression that has one of the following types:

-- a type compatible with the effective type of the object,
-- a qualified version of a type compatible with the effective type of the object,
-- a type that is the signed or unsigned type corresponding to the
   effective type of the object,
-- a type that is the signed or unsigned type corresponding to a
   qualified version of the effective type of the object,
-- an aggregate or union type that includes one of the aforementioned
   types among its members (including, recursively, a member of a
   subaggregate or contained union), or
-- a character type."

and this is exactly the one you are violating, since you're accessing struct
_LSPESn as STC.
Comment 2 Andrew Pinski 2005-06-05 08:27:20 UTC
Reopening to ...
Comment 3 Andrew Pinski 2005-06-05 08:27:36 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***