[Bug middle-end/43987] [4.5/4.6 Regression] type-punning causes broken binaries unless -O0 is used

rguenth at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed May 5 13:56:00 GMT 2010



------- Comment #15 from rguenth at gcc dot gnu dot org  2010-05-05 13:56 -------
Testcase that does not violate strict aliasing rules (and thus should not
be miscompiled at -O2 or -Os either):

extern char B[256 * sizeof(void *)];
typedef void *FILE;
typedef struct globals {
    int c;
    FILE **l;
} __attribute__((may_alias)) T;
void* xrealloc(void *vector, unsigned sizeof_and_shift, int idx);
void add_input_file(FILE *file)
{
  (*(T*)&B).l = xrealloc(((*(T*)&B).l),
                         (sizeof(((*(T*)&B).l)[0]) << 8) + (2),
                         ((*(T*)&B).c));
  (*(T*)&B).l[(*(T*)&B).c++] = file;
}


I have a patch.  Workaround for 4.5.0: -fno-pta.


-- 


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



More information about the Gcc-bugs mailing list