[Bug middle-end/45819] [4.5 Regression] unexpected unaligned access to volatile int

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 22 12:25:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45819

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #15 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-22 12:25:01 UTC ---
struct ehci_regs {                                                              
char x;                                                                         
unsigned int port_status[0];                                                    
} __attribute__ ((packed));                                                     
//} __attribute__ ((packed,aligned(__alignof__(int))));                         

struct ehci_hcd{                                                                
struct ehci_regs *regs;                                                         
};                                                                              

int ehci_hub_control (                                                          
 struct ehci_hcd *ehci,                                                         
 int wIndex                                                                     
) {                                                                             
 unsigned int *status_reg = &ehci->regs->port_status[wIndex];                   
 return *(volatile unsigned int *)status_reg;                                   
}

this one is invalid as well, with or without the aligned attribute.

ehci->regs->port_status[wIndex] _is_ unaligned.  I don't think there
is currently a way to tell GCC that the struct layout of ehci_regs is
packed but port_status is properly aligned to the natural alignment of int.



More information about the Gcc-bugs mailing list