From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 75F2E3858C3A; Sun, 3 Oct 2021 04:09:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75F2E3858C3A From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102573] optimized code removes the underlying elements of the std::initializer_list being copied Date: Sun, 03 Oct 2021 04:09:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.8.5 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: bug_status resolution 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Oct 2021 04:09:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102573 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Andrew Pinski --- GCC warns: : In function 'int main()': :9:19: warning: assignment from temporary 'initializer_list' does n= ot extend the lifetime of the underlying array [-Winit-list-lifetime] 9 | il =3D {111, 222}; | ^ Plus at runtime with -fsanitize=3Daddress: =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=3D1=3D=3DERROR: AddressSanitizer: stack-use-after-scope on address 0x7f= fcff6b4e10 at pc 0x00000040147d bp 0x7ffcff6b4dc0 sp 0x7ffcff6b4db8 READ of size 4 at 0x7ffcff6b4e10 thread T0 #0 0x40147c in main /app/example.cpp:13 #1 0x7f5915fc70b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) #2 0x40118d in _start (/app/output.s+0x40118d) Address 0x7ffcff6b4e10 is located in stack of thread T0 at offset 32 in fra= me #0 0x401255 in main /app/example.cpp:7 This frame has 2 object(s): [32, 40) '' <=3D=3D Memory access at offset 32 is inside this = variable [64, 80) 'il' (line 8) 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 /app/example.cpp:13 in main Shadow bytes around the buggy address: 0x10001fece970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fece980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fece990: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fece9a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fece9b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 =3D>0x10001fece9c0: f1 f1[f8]f2 f2 f2 00 00 f3 f3 00 00 00 00 00 00 0x10001fece9d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fece9e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fece9f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fecea00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10001fecea10: 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=3D1=3D=3DABORTING initializer_list size: 2 initializer_list underlying elements:=20 clang also errors out the same way.=