public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "13508417 at qq dot com" <gcc-bugzilla@gcc.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 05:49:32 +0000 [thread overview]
Message-ID: <bug-102573-4-aZMueUV5Vl@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102573-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102573
--- Comment #2 from wjf <13508417 at qq dot com> ---
(In reply to Andrew Pinski from comment #1)
> GCC warns:
> <source>: In function 'int main()':
> <source>:9:19: warning: assignment from temporary 'initializer_list' does
> not extend the lifetime of the underlying array [-Winit-list-lifetime]
> 9 | il = {111, 222};
> | ^
>
> Plus at runtime with -fsanitize=address:
>
> =================================================================
> ==1==ERROR: AddressSanitizer: stack-use-after-scope on address
> 0x7ffcff6b4e10 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 frame
> #0 0x401255 in main /app/example.cpp:7
>
> This frame has 2 object(s):
> [32, 40) '<unknown>' <== 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
> =>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
> 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
> ==1==ABORTING
> initializer_list size: 2
> initializer_list underlying elements:
>
>
> clang also errors out the same way.
----
Hi Andrew,
I know that adding "-fsanitize=address" could detect the stack-use-after-scope
in runtime. But why not just delete the copy member in std::initializer_list
implementation? I don't see much sense to permit the copy operation.
next prev parent reply other threads:[~2021-10-03 5:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-03 4:04 [Bug libstdc++/102573] New: " 13508417 at qq dot com
2021-10-03 4:09 ` [Bug libstdc++/102573] " pinskia at gcc dot gnu.org
2021-10-03 5:49 ` 13508417 at qq dot com [this message]
2021-10-03 6:20 ` pinskia at gcc dot gnu.org
2021-10-03 14:16 ` 13508417 at qq dot com
2021-10-04 6:55 ` redi at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-102573-4-aZMueUV5Vl@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).