This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

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):

        movl    $0, %eax

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]