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

--- Comment #13 from Mark Wielaard <mark at gcc dot gnu.org> ---
I could replicate this with gcc 9.1.1 with the following source:

#define variables  (const char* []){ "PK", "KEK", "db"}

int ret, len;

void isVariable(char *var)
{
  for (int v = 0; v < 2; v++)
    if (__builtin_strncmp(var,variables[v], 2) == 0)
      ret = 0;
}

int main(int argc, char* argv[])
{
//  __builtin_printf ("argv[0]=%s\n", argv[0]);
  isVariable(argv[0]);
  len = __builtin_strlen (argv[0]);
  return 0;
}

compiled with gcc -g -Os and valgrind from git trunk with --vgdb=full
--track-origins=yes:

==25741== Command: ./a.out
==25741== 
==25741== Use of uninitialised value of size 8
==25741==    at 0x10000504: main (pr9862.C:16)
==25741==  Uninitialised value was created by a stack allocation
==25741==    at 0x100006C4: isVariable(char*) (pr9862.C:6)
==25741== 

Disassambly of main and isVariable

Dump of assembler code for function main(int, char**):
   0x00000000100004e0 <+0>:     lis     r2,4098
   0x00000000100004e4 <+4>:     addi    r2,r2,32512
   0x00000000100004e8 <+8>:     mflr    r0
   0x00000000100004ec <+12>:    std     r31,-8(r1)
   0x00000000100004f0 <+16>:    ld      r3,0(r4)
   0x00000000100004f4 <+20>:    mr      r31,r4
   0x00000000100004f8 <+24>:    std     r0,16(r1)
   0x00000000100004fc <+28>:    stdu    r1,-48(r1)
   0x0000000010000500 <+32>:    bl      0x100006b4 <isVariable(char*)+8>
   0x0000000010000504 <+36>:    ld      r3,0(r31)
   0x0000000010000508 <+40>:    bl      0x100004a0
<00000023.plt_call.strlen@@GLIBC_2.17>
   0x000000001000050c <+44>:    ld      r2,24(r1)
   0x0000000010000510 <+48>:    nop
   0x0000000010000514 <+52>:    addi    r1,r1,48
   0x0000000010000518 <+56>:    stw     r3,-32452(r2)
   0x000000001000051c <+60>:    li      r3,0
   0x0000000010000520 <+64>:    b       0x1000086c <_restgpr0_31>
   0x0000000010000524 <+68>:    .long 0x0
   0x0000000010000528 <+72>:    .long 0x1000900
   0x000000001000052c <+76>:    .long 0x180
End of assembler dump.

Dump of assembler code for function isVariable(char*):
   0x00000000100006ac <+0>:     lis     r2,4098
   0x00000000100006b0 <+4>:     addi    r2,r2,32512
   0x00000000100006b4 <+8>:     mflr    r0
   0x00000000100006b8 <+12>:    addis   r9,r2,-2
   0x00000000100006bc <+16>:    addi    r9,r9,-30152
   0x00000000100006c0 <+20>:    bl      0x10000820 <_savegpr0_25>
   0x00000000100006c4 <+24>:    stdu    r1,-128(r1)
   0x00000000100006c8 <+28>:    ld      r29,0(r9)
   0x00000000100006cc <+32>:    ld      r28,8(r9)
   0x00000000100006d0 <+36>:    nop
   0x00000000100006d4 <+40>:    mr      r30,r3
   0x00000000100006d8 <+44>:    ld      r27,16(r9)
   0x00000000100006dc <+48>:    li      r31,0
   0x00000000100006e0 <+52>:    addi    r25,r2,-32456
   0x00000000100006e4 <+56>:    addi    r26,r1,32
   0x00000000100006e8 <+60>:    std     r29,32(r1)
   0x00000000100006ec <+64>:    std     r28,40(r1)
   0x00000000100006f0 <+68>:    rldicr  r9,r31,3,60
   0x00000000100006f4 <+72>:    li      r5,2
   0x00000000100006f8 <+76>:    std     r27,48(r1)
   0x00000000100006fc <+80>:    mr      r3,r30
   0x0000000010000700 <+84>:    ldx     r4,r26,r9
   0x0000000010000704 <+88>:    bl      0x100004c0
<00000023.plt_call.strncmp@@GLIBC_2.17>
   0x0000000010000708 <+92>:    ld      r2,24(r1)
   0x000000001000070c <+96>:    mr.     r9,r3
   0x0000000010000710 <+100>:   bne     0x10000718 <isVariable(char*)+108>
   0x0000000010000714 <+104>:   stw     r9,0(r25)
   0x0000000010000718 <+108>:   cmpldi  r31,1
   0x000000001000071c <+112>:   bne     0x10000728 <isVariable(char*)+124>
   0x0000000010000720 <+116>:   addi    r1,r1,128
   0x0000000010000724 <+120>:   b       0x10000844 <_restgpr0_25>
   0x0000000010000728 <+124>:   li      r31,1
   0x000000001000072c <+128>:   b       0x100006e8 <isVariable(char*)+60>
   0x0000000010000730 <+132>:   .long 0x0
   0x0000000010000734 <+136>:   .long 0x1000900
   0x0000000010000738 <+140>:   .long 0x780
End of assembler dump.

Reply via email to