[Bug c/24931] New: uninitialized structure member after assignment

dylan at dylex dot net gcc-bugzilla@gcc.gnu.org
Fri Nov 18 05:53:00 GMT 2005


Consider this code:

struct p {
        short x, y;
};

struct s {
        int i;
        struct p p;
};

struct s f()
{
        struct s s;
        s.p = (struct p){};
        s.i = (s.p.x || s.p.y);
        return s;
}

When compiled with gcc -Wall -O -c, it reports:
t.c: In function 'f':
t.c:14: warning: 's.i' is used uninitialized in this function

That's not right.  Furthermore, I think the generated assembly might be wrong
(this is with -O):

f:
        movl    $0, %eax
        ret

The return value should be a full 64 bits (%rax), but only the bottom 32 are
initialized (unless this clears the high ones on x86_64 or the calling
convention says they are already -- I don't really know).


-- 
           Summary: uninitialized structure member after assignment
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dylan at dylex dot net
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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



More information about the Gcc-bugs mailing list