<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111626>111626</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crashes at -O0 on x86_64-linux-gnu
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bi6c
</td>
</tr>
</table>
<pre>
Compiler Explorer: https://godbolt.org/z/74WYz7xW6
```console
<source>:6:25: warning: implicit conversion from 'unsigned int' to 'char' changes value from 3735928559 to -17 [-Wconstant-conversion]
6 | *shouldnotcompile = 0xDEADBEEF; // Force compiler error/warning with unaligned memory write attempt, to make it easier for testers and authors.
| ~ ^~~~~~~~~~
LLVM ERROR: out of memory
Allocation failed
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -fsanitize=undefined -fsanitize=address -O0 <source>
1. <eof> parser at end of file
2. Optimizer
3. Running pass "asan<>" on module "<source>"
#0 0x00000000039400a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x39400a8)
#1 0x000000000393e214 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x393e214)
#2 0x0000000003890678 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007ff1e6842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007ff1e68969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007ff1e6842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007ff1e68287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000000000389ae80 out_of_memory_new_handler() ErrorHandling.cpp:0:0
#8 0x00000000038bce3d llvm::SmallVectorBase<unsigned long>::grow_pod(void*, unsigned long, unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bce3d)
#9 0x0000000003980274 llvm::GetShadowBytes(llvm::SmallVectorImpl<llvm::ASanStackVariableDescription> const&, llvm::ASanStackFrameLayout const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3980274)
#10 0x0000000003980316 llvm::GetShadowBytesAfterScope(llvm::SmallVectorImpl<llvm::ASanStackVariableDescription> const&, llvm::ASanStackFrameLayout const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3980316)
#11 0x00000000035ec629 (anonymous namespace)::FunctionStackPoisoner::processStaticAllocas() AddressSanitizer.cpp:0:0
#12 0x00000000035efba3 (anonymous namespace)::FunctionStackPoisoner::runOnFunction() AddressSanitizer.cpp:0:0
#13 0x00000000035f2c33 (anonymous namespace)::AddressSanitizer::instrumentFunction(llvm::Function&, llvm::TargetLibraryInfo const*) AddressSanitizer.cpp:0:0
#14 0x00000000035f4855 llvm::AddressSanitizerPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x35f4855)
#15 0x0000000003bc901e llvm::detail::PassModel<llvm::Module, llvm::AddressSanitizerPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3bc901e)
#16 0x0000000003313137 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3313137)
#17 0x0000000003bd85eb (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#18 0x0000000003bdb91f clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3bdb91f)
#19 0x000000000425c554 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x425c554)
#20 0x0000000006228cfc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x6228cfc)
#21 0x000000000425cc75 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x425cc75)
#22 0x0000000004524651 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x4524651)
#23 0x00000000044a429b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x44a429b)
#24 0x0000000004608bb3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4608bb3)
#25 0x0000000000ce032c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xce032c)
#26 0x0000000000cd8d8d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00000000042a5419 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#28 0x0000000003890aa3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3890aa3)
#29 0x00000000042a5639 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#30 0x000000000426c87d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x426c87d)
#31 0x000000000426d87d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x426d87d)
#32 0x00000000042772cc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42772cc)
#33 0x0000000000cdd081 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xcdd081)
#34 0x0000000000bb0634 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xbb0634)
#35 0x00007ff1e6829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#36 0x00007ff1e6829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#37 0x0000000000cd882e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xcd882e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
Code:
```c
#include <stdio.h>
__attribute__((always_inline))
inline void fail() {
char* shouldnotcompile = (char*)-512;
*shouldnotcompile = 0xDEADBEEF; // Force compiler error/warning with unaligned memory write attempt, to make it easier for testers and authors.
}
int main(int argc, char** argv) {
(void)(argc); // Eliminate \'argc unused\' warning.
void* arr = __builtin_alloca((sizeof(char) * -1024) + 512); // Cause "argument to ‘__builtin_alloca’ is too large" error with some compilers for educational purposes and create unaligned/offset memory layout (warning).
char *victim;
#ifdef __LITTLE_ENDIAN__
victim = ((char*) arr) + 1; // Set a pointer just before our aligned data structure, forcing the possibility of stack alignment warnings.
#else
victim = ((char*) arr);
#endif
fail();
printf("I didn\'t expect to reach this line.\
"); // Only used for error analysis if above warning/error-prone section doesn\'t generate desired effect in compiler messages (should never be executed anyway).
return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWktz4ziS_jXwBSEHBVIUefBBlqXp6nBPVVie7tgTAwSTEqZIgAuAtlWH-e0bAKgHaLlertjd2XXMdNkgHl9--WUiQYJqzbcC4AbNbtHs7or2ZifVTclTdlXKan-zlG3HG1B49dI1UoFC8QLvjOk0iheIrBFZb2VVysZcS7VFZP0FkfU8-es_vsxf_kpRdIeiBUoj_z8mhZYNDK3xUsteMUDxCsWLFMULMrOzP1MluNjaX3nbNZxxg5kUT6A0lwLXSrYYkXkvHPQKc2EQmWMjbSvbUWX_YjsqtqDxE2168GPieTzLSTab5bbvZDrHaHY7-cuCMlSYyWkNNLvzGDHGOMVovrS_YEQWeif7phLSMM8LRvEdjl7uVou729VqjeJb7EnBa6kYYHagD5SSCpH1YBx-5maHe0Ebb0MLrVR7_Ky4AUyNgbYziCwt0JZ-BswNBqo5KFxLhQ1oA0pjKirsPaavT4DxEfDrn39hNFv96_Djx9zf__kHXj08fHywlMveYFkPgHyHRdNIRo0jn_IGKt_86X612Kyw7suWG0xx2W-xgk4qY2GPNMLNri-vmWwRWTfN0-GfSafkP4EZRNZc6x60pc6axQVr-gqw2QFmiuodLin7bBRlYHnpFHRKMtAaKjzIiCw9IVpLxqmBCqteYM0U78xAz8ZQ9hlXfdtZZK4pukZR_knJraItpmrbtyCMBW4dKa0X1gcnTuAQA2TNGiq2E6N68RmRdcnFoQ1PttUzVfUkwZMtnlhRrmnX2cl60_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