<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121704>121704</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
lto=full + address sanitizer results in free/delete errors
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Oipo
</td>
</tr>
</table>
<pre>
clang version: 19
When compiling with lto=full and address sanitizer, I get weird errors:
```
$ ../bin/CoroutineTests
... program executes as normal ...
free(): invalid size
Aborted (core dumped)
```
```
$ ../bin/CoroutineTests_sdevent
... program executes as normal ...
munmap_chunk(): invalid pointer
Aborted (core dumped)
```
```
$ ../bin/AsyncFileIOTests
... program executes as normal ...
=================================================================
==3074019==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 376 byte(s) in 1 object(s) allocated from:
#0 0x3f2edd in operator new(unsigned long) crtstuff.c
#1 0x6473c9 in Catch::Detail::unique_ptr<std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>> Catch::Detail::make_unique<std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>>() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/internal/catch_unique_ptr.hpp:111:30
#2 0x6473c9 in Catch::StringStreams::add() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_reusable_string_stream.cpp:26:38
#3 0x6473c9 in Catch::ReusableStringStream::ReusableStringStream() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_reusable_string_stream.cpp:43:57
#4 0x57dd08 in Catch::TablePrinter::TablePrinter(std::ostream&, std::vector<Catch::ColumnInfo, std::allocator<Catch::ColumnInfo>>) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/reporters/catch_reporter_console.cpp:305:5
#5 0x57dd08 in Catch::Detail::unique_ptr<Catch::TablePrinter> Catch::Detail::make_unique<Catch::TablePrinter, std::ostream&, std::vector<Catch::ColumnInfo, std::allocator<Catch::ColumnInfo>>>(std::ostream&, std::vector<Catch::ColumnInfo, std::allocator<Catch::ColumnInfo>>&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/internal/catch_unique_ptr.hpp:111:34
#6 0x57dd08 in Catch::ConsoleReporter::ConsoleReporter(Catch::ReporterConfig&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/reporters/catch_reporter_console.cpp:381:20
#7 0x63e291 in Catch::Detail::unique_ptr<Catch::ConsoleReporter> Catch::Detail::make_unique<Catch::ConsoleReporter, Catch::ReporterConfig>(Catch::ReporterConfig&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/internal/catch_unique_ptr.hpp:111:34
#8 0x63e291 in Catch::ReporterFactory<Catch::ConsoleReporter>::create(Catch::ReporterConfig&&) const /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/reporters/catch_reporter_registrars.hpp:48:20
#9 0x5defab in Catch::ReporterRegistry::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Catch::ReporterConfig&&) const /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_reporter_registry.cpp:62:28
#10 0x5defab in Catch::(anonymous namespace)::createReporter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Catch::ReporterConfig&&) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:46:75
#11 0x5dc174 in Catch::(anonymous namespace)::prepareReporters(Catch::Config const*) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:56:24
#12 0x5dc174 in Catch::Session::runInternal() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:320:29
#13 0x5db471 in Catch::Session::run() /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/catch_session.cpp:269:24
#14 0x56ad1b in int Catch::Session::run<char>(int, char const* const*) /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/../catch2/catch_session.hpp:41:30
#15 0x56ad1b in main /home/githubrunner/actions-runner/_work/Ichor/Ichor/build/src/catch2/internal/catch_main.cpp:36:29
#16 0x7f0733b8ed8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
SUMMARY: AddressSanitizer: 376 byte(s) leaked in 1 allocation(s).
```
All of these errors disappear if I remove either lto or address sanitizer.
Source file compilation:
```
/usr/bin/clang++-19 -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_SANITIZE_VECTOR -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST -D__SANITIZE_ADDRESS__ -I/home/oipo/Programming/Ichor/external/Catch2/src/catch2/.. -I/home/oipo/Programming/Ichor/build/external/Catch2/generated-includes -O3 -ggdb3 -DNDEBUG -flto=full -ffile-prefix-map=/home/oipo/Programming/Ichor/external/Catch2/= -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=vptr -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -std=c++2b -MD -MT external/Catch2/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_templated.cpp.o -MF external/Catch2/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_templated.cpp.o.d -o external/Catch2/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_templated.cpp.o -c /home/oipo/Programming/Ichor/external/Catch2/src/catch2/matchers/catch_matchers_templated.cpp
```
Linking:
```
/usr/bin/clang++-19 -O3 -ggdb3 -DNDEBUG -flto=full -Wl,--exclude-libs,ALL -fsanitize=address,undefined -no-pie -Wl,-z,nodlopen -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -Wl,--no-copy-dt-needed-entries test/CMakeFiles/AsyncFileIOTests.dir/AsyncFileIOTests.cpp.o -o /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/AsyncFileIOTests /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/libichor.a /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/libCatch2Main.a -lsystemd -ldl -lrt /home/githubrunner/actions-runner/_work/Ichor/Ichor/bin/libCatch2.a
```
I don't really know how to make a minimally reproducible case here, as I can't trigger this without the combination of Catch2 and my source code. If I leave out Catch2, it doesn't trigger either. Please let me know what I could do to improve this report.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWV9v2zgS_zTMy0CCRPnvQx5UO94z0DSFnd7u3otAiSObF4rUkVQS76c_UJJdO4m76W2a7gFGYg9FcubH3_zRkFkrNgrxkgw_kOH8gjVuq83ljaj1Ra757rKQTG3gHo0VWpEkhXhKopRE6a9bVFDoqhZSqA08CLcF6TRJ5mUjJTDFgXFu0FqwTAkn_kBD6AyWsEEHDygMBzRGG0sSvx4ZRf0nSgkdQBgSusiFInQx00Y3Tii8RessidIwDKE2emNYBfiIRePQArOgtKmYhDAMSZSWBpHQCaFTr7ZQ90wKDlb8gSRK01wbhxwInRTaIPCmqpH7Z59o8lqtMsvxHpV7rXZVoypWZ8W2UXfPtay1UA7N2yia2p0qFkLi8ua7ACTJ_P_-s7ciicaDKJ52P65Wq5uVh_sjsrv1gZxJChwdFh7uCittdiCR3dmO73NhsHCtBHQJyXgE-c55hllCpyAUxKDzf2Ph9iImpS6YX600uupYDgBAaBJB9JiUFDn3E3WNhjltQOEDoZNGtT7JQWq18QsVxlnXlGVYfF0hhuhxNBgnRbv1jLli63dI0jk6JmT3vVHiPw1mtTMkmVnHO2mWFY-Pcdz9yJkVRaatM0JtrDPIKpLMii1rnfUwxwsyZ5hwdj-cXJ080VurzdF4-zmnXMXuMOs0_Inadb4HhC62ukJCFxvhtk1uGqV8vFqwwgmtbHAQZA_a3BG6WBZbbY7-542QnNCFNQWhi8LbTAldtH54-NV6tWJyL8u-nlC4rWuSpHFreuLd2B8zPXfM6xaSdQuJ7W3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