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

--- Comment #3 from Sam James <sjames at gcc dot gnu.org> ---
Fails with -fno-strict-aliasing too.

With Valgrind when (maybe) miscompiled:
```
==164909== Conditional jump or move depends on uninitialised value(s)
==164909==    at 0x10A5E2: realsmith_proxy_j8M9c (in /tmp/a)
==164909==    by 0x10A6A8: func_2.isra.0 (in /tmp/a)
==164909==    by 0x10CB56: func_1.isra.0 (in /tmp/a)
==164909==    by 0x108375: main (in /tmp/a)
==164909==
==164909== Conditional jump or move depends on uninitialised value(s)
==164909==    at 0x10A614: realsmith_proxy_j8M9c (in /tmp/a)
==164909==    by 0x10A6A8: func_2.isra.0 (in /tmp/a)
==164909==    by 0x10CB56: func_1.isra.0 (in /tmp/a)
==164909==    by 0x108375: main (in /tmp/a)
==164909==
==164909== Conditional jump or move depends on uninitialised value(s)
==164909==    at 0x10A60F: realsmith_proxy_j8M9c (in /tmp/a)
==164909==    by 0x10A6A8: func_2.isra.0 (in /tmp/a)
==164909==    by 0x10CB56: func_1.isra.0 (in /tmp/a)
==164909==    by 0x108375: main (in /tmp/a)
```

With GCC trunk asan+ubsan with -O3 -fno-stack-protector -fno-strict-aliasing
(so in theory not miscompiled):
```
==165062==ERROR: AddressSanitizer: stack-use-after-return on address
0x71feb7101020 at pc 0x5f8e5041002d bp 0x7ffc14e9c610 sp 0x7ffc14e9c600
READ of size 4 at 0x71feb7101020 thread T0
    #0 0x5f8e5041002c in main (/tmp/a+0xa02c)
    #1 0x75feb9205746 in __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
    #2 0x75feb92057f6 in __libc_start_main_impl ../csu/libc-start.c:360
    #3 0x5f8e50411f20 in _start (/tmp/a+0xbf20)

Address 0x71feb7101020 is located in stack of thread T0 at offset 32 in frame
    #0 0x5f8e5041c70f in func_14.constprop.0.isra.0 (/tmp/a+0x1670f)

  This frame has 14 object(s):
    [32, 36) 'l_985' (line 3338) <== Memory access at offset 32 is inside this
variable
    [48, 52) 'p_0_EnthG' (line 3333)
    [64, 68) 'p_1_Unkxz' (line 3333)
    [80, 88) 'l_1048' (line 3343)
    [112, 120) 'l_1160' (line 3344)
    [144, 152) 'l_1016' (line 3385)
    [176, 186) 'proxy_hzikI'
    [208, 220) 'l_1046' (line 3408)
    [240, 264) 'l_1068' (line 3386)
    [304, 356) 'proxy_J0MGc'
    [400, 456) 'l_986' (line 3358)
    [496, 556) 'proxy_1ZFFb'
    [592, 672) 'l_1208' (line 3346)
    [704, 2648) 'l_1209' (line 3345)
HINT: this may be a false positive if your program uses some custom stack
unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return (/tmp/a+0xa02c) in main
Shadow bytes around the buggy address:
  0x71feb7100d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x71feb7100e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x71feb7100e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x71feb7100f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x71feb7100f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x71feb7101000: f5 f5 f5 f5[f5]f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x71feb7101080: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x71feb7101100: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x71feb7101180: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x71feb7101200: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x71feb7101280: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
```

Reply via email to