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

            Bug ID: 108510
           Summary: ASAN missed a stack-use-after-scope at -O1
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

For the following code, GCC's ASAN at -O1 missed the stack-use-after-scope,
while other opt levels detected it.

I checked the assembly code, -O1 didn't optimize away the buggy code.

Compiler explorer: https://godbolt.org/z/jWPG8hMWY

% cat a.c
short a;
char b;
short *c = &a, *d;
long e;
int main() {
  long *f = &e;
  {
    int g=0;
    d = &g;
  }
  *d << (b = ((*f)--, c || *d));
}
%
% gcc-tk -fsanitize=address -g -O1 a.c && ./a.out
%
% gcc-tk -fsanitize=address -g -O2 a.c && ./a.out
=================================================================
==1==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7f0150b00020
at pc 0x0000004011a4 bp 0x7ffff43bc150 sp 0x7ffff43bc148
READ of size 2 at 0x7f0150b00020 thread T0
    #0 0x4011a3 in main /a.c:11
    #1 0x7f01534e6082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #2 0x40123d in _start (/app/output.s+0x40123d) (BuildId:
2f09fd97ce9e5ec29ed33980daf91dfdd4bb3ebc)

Address 0x7f0150b00020 is located in stack of thread T0 at offset 32 in frame
    #0 0x4010bf in main /a.c:5
...
%

Reply via email to