public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104384] New: Heap corruption when initializing struct with co_await
@ 2022-02-04 15:25 max at duempel dot org
  2023-04-22 19:41 ` [Bug c++/104384] coroutines: " StevenSun2021 at hotmail dot com
  2024-05-06  6:27 ` accelerator0099 at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: max at duempel dot org @ 2022-02-04 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104384
           Summary: Heap corruption when initializing struct with co_await
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: max at duempel dot org
  Target Milestone: ---

Created attachment 52350
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52350&action=edit
Crashing demo program

When initializing struct members, and one struct member gets initialized with a
co_awaited values, the following struct members can be corrupted.

Tested with:
- gcc version 10.2.1 20210110 (Debian 10.2.1-6) 
- gcc version 11.2.0 (Debian 11.2.0-16) 
- gcc version 12.0.1 20220126 (experimental) [master r12-6872-gf3e6ef7d873]
(Debian 12-20220126-1) 

clang ("Debian clang version 11.0.1-2") is fine.

My demo program crashes like this:

$ g++ -o cocrash2 cocrash2.cxx  -fcoroutines -std=c++20 && valgrind ./cocrash2 
==1947496== Memcheck, a memory error detector
==1947496== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1947496== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==1947496== Command: ./cocrash2
==1947496== 
==1947496== Invalid free() / delete / delete[] / realloc()
==1947496==    at 0x484008B: operator delete(void*, unsigned long) (in
/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1947496==    by 0x10C438: __gnu_cxx::new_allocator<char>::deallocate(char*,
unsigned long) (in /tmp/cocrash2)
==1947496==    by 0x10C0EC: std::allocator_traits<std::allocator<char>
>::deallocate(std::allocator<char>&, char*, unsigned long) (in /tmp/cocrash2)
==1947496==    by 0x10BE29: std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::_M_destroy(unsigned long) (in
/tmp/cocrash2)
==1947496==    by 0x10B973: std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::_M_dispose() (in /tmp/cocrash2)
==1947496==    by 0x10B167: std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::~basic_string() (in
/tmp/cocrash2)
==1947496==    by 0x10AE5F: Foo::~Foo() (in /tmp/cocrash2)
==1947496==    by 0x10AA61: main (in /tmp/cocrash2)
==1947496==  Address 0x4db6d20 is 160 bytes inside a block of size 200 alloc'd
==1947496==    at 0x483EDEF: operator new(unsigned long) (in
/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1947496==    by 0x10A593: MakeFoo(bool) (in /tmp/cocrash2)
==1947496==    by 0x10A9F3: main (in /tmp/cocrash2)
==1947496==

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/104384] coroutines: Heap corruption when initializing struct with co_await
  2022-02-04 15:25 [Bug c++/104384] New: Heap corruption when initializing struct with co_await max at duempel dot org
@ 2023-04-22 19:41 ` StevenSun2021 at hotmail dot com
  2024-05-06  6:27 ` accelerator0099 at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: StevenSun2021 at hotmail dot com @ 2023-04-22 19:41 UTC (permalink / raw)
  To: gcc-bugs

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

Steven Sun <StevenSun2021 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |StevenSun2021 at hotmail dot com

--- Comment #1 from Steven Sun <StevenSun2021 at hotmail dot com> ---
seems that 103909, 104384, 107288 are related (probably the same bug)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/104384] coroutines: Heap corruption when initializing struct with co_await
  2022-02-04 15:25 [Bug c++/104384] New: Heap corruption when initializing struct with co_await max at duempel dot org
  2023-04-22 19:41 ` [Bug c++/104384] coroutines: " StevenSun2021 at hotmail dot com
@ 2024-05-06  6:27 ` accelerator0099 at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: accelerator0099 at gmail dot com @ 2024-05-06  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

accelerator0099 at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |accelerator0099 at gmail dot com

--- Comment #2 from accelerator0099 at gmail dot com ---
No error on GCC 13.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-06  6:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 15:25 [Bug c++/104384] New: Heap corruption when initializing struct with co_await max at duempel dot org
2023-04-22 19:41 ` [Bug c++/104384] coroutines: " StevenSun2021 at hotmail dot com
2024-05-06  6:27 ` accelerator0099 at gmail dot com

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).