[Bug c/49768] C99 style union initializations does not work as expected with optimizations

mikpe at it dot uu.se gcc-bugzilla@gcc.gnu.org
Sun Jul 17 12:47:00 GMT 2011


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

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2011-07-17 12:47:17 UTC ---
Created attachment 24780
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24780
reduced test case

This reduced test case doesn't use any union, just a struct with two one-bit
fields, and fails at -O1 and above with 4.6 and 4.7 on i686-linux.  Looking at
the generated code, gcc has removed all runtime checks and just inserted a call
to abort.

/* pr49768.c */

int main(void)
{
    static struct {
        unsigned int :1;
        unsigned int test_bit2:1;
    } test = {
        .test_bit2 = 1,
    };

    if (test.test_bit2 != 1)
        __builtin_abort();

    return 0;
}



More information about the Gcc-bugs mailing list