------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-28 14:19 
-------
Confirmed, a regression but I don't know if this is a middle-end problem or a 
front-end problem.
The front-end produces the following code:
    struct S obj[2] = {{.s=(const char *) "m0"}, {}};

This is a middle-end (the gimplifier) issue as the C front-end has the same problem 
(the C standard 
defines it in 6.7.8/21).

The C example:
#include <stdio.h>

typedef struct S {
    const char* s;
    int         i;
} S;

void foo() {
    // Put some garbage on the stack
    S dummy[2];
    for (unsigned i = 0; i < sizeof(dummy); i++)
        ((char *)&dummy)[i] = -1;
}

int bar() {
    // Allocate object on the stack
    S obj[2] = {
        {"m0"},
        { }
    };
    // Assume fields those not explicitly initialized
    // are default initialized to 0 [8.5.1/7 and 8.5/5]
    if (obj[0].i == 0){
        return 0;
    } else {
        printf("Failed: obj[0].i == '%d', expecting '0'\n", obj[0].i);
        return 1;
    }
};

int main(){
    foo();
    return bar();
}

Note we get a warning which is bogus:
pr18191.c:23: warning: 'obj$0$i' is used uninitialized in this function

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |middle-end
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-28 14:19:42
               date|                            |
            Summary|Struct member is not getting|[4.0 Regression] Struct
                   |default-initialized         |member is not getting
                   |                            |default-initialized
   Target Milestone|---                         |4.0.0


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

Reply via email to