From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EF490383F08B; Tue, 13 Dec 2022 16:08:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF490383F08B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670947717; bh=qQ52PJlyZYPoJdomMsO0KPWWBsOg89btCN+wKAksJx4=; h=From:To:Subject:Date:From; b=uDl7r8pr5G8UBxgFA5Tu2OEQxaQvVkXg+xrXI1uVnyqr5pg2UCVRtYO5hPn0LJzsP jel//odqOPI2l7dGwHfXKLyocyt0AFN2omBFoxgMXR6r6K74YdXh80L20ZzsxfKqmm bIeURpZjtqklHJHMQbt9d8KTJuSoGg7999BaQ4oo= From: "shaohua.li at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope Date: Tue, 13 Dec 2022 16:08:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: shaohua.li at inf dot ethz.ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108085 Bug ID: 108085 Summary: gcc trunk's ASAN at -O3 missed a stack-use-after-scope 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, marxi= n at gcc dot gnu.org Target Milestone: --- For the following code, ASAN at -O3 failed to report the stack-use-after-sc= ope, other opt levels detected it successfully. GCC-8 works fine.=20 Clang at all optimization levels reported it. Compiler explorer: https://godbolt.org/z/jbsThYWa6 % cat a.c int a; void b() { int c[1]; c; } int main() { int d[1]=3D{1}; int *e =3D d; a =3D 0; for (; a <=3D 5; ++a) { int f[1]=3D{}; e =3D f; a || (b(), 1); } return *e; } % % gcc-tk -O2 -fsanitize=3Daddress -g a.c && ./a.out =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D780198=3D=3DERROR: AddressSanitizer: stack-use-after-scope on address 0x7f2307600030 at pc 0x0000004011c5 bp 0x7ffdd19ecd80 sp 0x7ffdd19ecd78 READ of size 4 at 0x7f2307600030 thread T0 #0 0x4011c4 in main /a.c:15 #1 0x7f2309f41082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #2 0x40126d in _start (/a.out+0x40126d) Address 0x7f2307600030 is located in stack of thread T0 at offset 48 in fra= me #0 0x4010bf in main /a.c:6 This frame has 3 object(s): [32, 36) 'd' (line 7) [48, 52) 'f' (line 11) <=3D=3D Memory access at offset 48 is inside this variable [64, 68) 'c' (line 3) ... % % gcc-tk -O3 -fsanitize=3Daddress -g a.c && ./a.out %=