https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70013

            Bug ID: 70013
           Summary: packed structure tree-sra loses initialization
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amodra at gmail dot com
  Target Milestone: ---

Seen on powerpc64le-linux at -O1 -Wall

#pragma pack(1)
struct S0 {
  unsigned f0 : 17;
};

int c;

int main(void)
{
  struct S0 d[] = { { 1 }, { 2 } };
  struct S0 e = d[1];

  c = d[0].f0;
  __builtin_printf("%x\n", e.f0);
  return 0;
}

pack2.c: In function 'main':
pack2.c:10:13: warning: '*((void *)&d+3).f0' is used uninitialized in this
function [-Wuninitialized]
   struct S0 d[] = { { 1 }, { 2 } };
             ^

and there is an uninitialized read from the stack
main:
.LCF0:
0:      addis 2,12,.TOC.-.LCF0@ha
        addi 2,2,.TOC.-.LCF0@l
        .localentry     main,.-main
        mflr 0
        std 0,16(1)
        stdu 1,-112(1)
        ld 4,96(1) # <--------  here.

tree-sra dump shows

main ()
{
  <unnamed-unsigned:17> SR.5;
  <unnamed-unsigned:17> d$3$f0;
  <unnamed-unsigned:17> e$f0;
  <unnamed-unsigned:17> d$0$f0;
  struct S0 d[2];
  int _3;
  int _5;

  <bb 2>:
  SR.5_12 = MEM[(struct S0[2] *)&*.LC0].f0;
  MEM[(struct S0[2] *)&d].f0 = SR.5_12;
  d$3$f0_14 = MEM[(struct S0[2] *)&d + 3B].f0;
  d$0$f0_7 = SR.5_12;
  e$f0_9 = d$3$f0_14;
  _3 = (int) d$0$f0_7;
  c = _3;
  _5 = (int) e$f0_9;
  printf ("%x\n", _5);
  d ={v} {CLOBBER};
  return 0;

}

So d[0] is written from the constant mem, but d[1] is read without first being
written.

Reply via email to