From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BB2E63858D33; Tue, 11 Apr 2023 10:36:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB2E63858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681209374; bh=12dcC9tVDMspogSj2g9JvXWmylDNu/hZOx1MJMFG8v4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gKvkQ9cjHzgib2sL275ts5uZsCQFkXojthiI9BK/PTmRqjIyWcKWTPpPPjVsJWARx 8jRo/8xfp4qAn5qnPaOWZtPrXjxlNt8Ibn8qbUj4BhHLG8lSRZeBvADeyB29Wg6gI2 +3TXZQff3dmnpdwdo2gtfYHr9rOxTEbuNV6/5m/w= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109470] unexpected const & behavior Date: Tue, 11 Apr 2023 10:36:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: cc Message-ID: In-Reply-To: References: 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=3D109470 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #7 from Jakub Jelinek --- You can use -fsanitize=3Daddress to get such bugs diagnosed at runtime: g++ -fsanitize=3Daddress -o /tmp/pr109470{,.C} -g; /tmp/pr109470 =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=3D2466554=3D=3DERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe08313d80 at pc 0x000000401304 bp 0x7ffe08313d20 sp 0x7ffe08313d18 READ of size 4 at 0x7ffe08313d80 thread T0 #0 0x401303 in main /tmp/pr109470.C:17 #1 0x7f5b06f7958f in __libc_start_call_main (/lib64/libc.so.6+0x2958f) #2 0x7f5b06f79648 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x29648) #3 0x4010e4 in _start (/tmp/pr109470+0x4010e4) Address 0x7ffe08313d80 is located in stack of thread T0 at offset 64 in fra= me #0 0x4011b5 in main /tmp/pr109470.C:12 This frame has 2 object(s): [48, 52) 'MAX' (line 14) [64, 68) '' <=3D=3D Memory access at offset 64 is inside this = variable 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-scope /tmp/pr109470.C:17 in main Shadow bytes around the buggy address: 0x10004105a760: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a770: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a790: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a7a0: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f1 f1 04 f2 =3D>0x10004105a7b0:[f8]f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a7c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a7d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a7e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a7f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10004105a800: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07=20 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb =3D=3D2466554=3D=3DABORTING C++ has always behaved like this and changing it would significantly penali= ze all the code in the wild that uses C++ correctly. There are some exceptions where the lifetime is extended, but is certainly not one of them.=