<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63000>63000</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86_64] trigger CrashRecoverySignalHandler when compile code with customized `alloc`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zxcuiop
</td>
</tr>
</table>
<pre>
With O1 optimization level, Clang crashed when compiling the following code due to an unaligned load (can be verified at https://gcc.godbolt.org/z/cG4Ka9hEG):
```
double *walloc(int len, int align) __attribute__((__alloc_align__(2)));
void f(int len) {
double *a = walloc(len, 32);
double *b = walloc(len, 32);
double *c = walloc(len, 0);
for (int i; i < len; ++i) {
a[i] = b[i] * c[i];
}
}
```
The following is the compiler's output, copied from gcc.godbolt.org:
```
<source>:6:27: warning: requested alignment is not a power of 2 [-Wnon-power-of-two-alignment]
double *c = walloc(len, 0);
^
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-14.0.0/bin/clang -gdwarf-4 -g -o /app/output.s -c --gcc-toolchain=/opt/compiler-explorer/gcc-11.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O2 <source>
1. <eof> parser at end of file
2. Optimizer
#0 0x00005557e4d7de8f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x00005557e4d7bd60 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x357bd60)
#2 0x00005557e4cb6b78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fb7ce592420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00005557e4c962aa llvm::APInt::setBitsSlowCase(unsigned int, unsigned int) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x34962aa)
#5 0x00005557e3ebb3b4 computeKnownBitsFromAssume(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#6 0x00005557e3ebcd3f computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#7 0x00005557e3ebd220 computeKnownBits(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#8 0x00005557e3ec5e07 computeKnownBitsFromOperator(llvm::Operator const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#9 0x00005557e3ebd150 computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#10 0x00005557e3ebd220 computeKnownBits(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#11 0x00005557e3ebf624 computeKnownBits(llvm::Value const*, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#12 0x00005557e3ebf6dd llvm::computeKnownBits(llvm::Value const*, llvm::DataLayout const&, unsigned int, llvm::AssumptionCache*, llvm::Instruction const*, llvm::DominatorTree const*, llvm::OptimizationRemarkEmitter*, bool) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x26bf6dd)
#13 0x00005557e4e46625 llvm::getOrEnforceKnownAlignment(llvm::Value*, llvm::MaybeAlign, llvm::DataLayout const&, llvm::Instruction const*, llvm::AssumptionCache*, llvm::DominatorTree const*) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3646625)
#14 0x00005557e47e6b8b llvm::InstCombinerImpl::visitLoadInst(llvm::LoadInst&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x2fe6b8b)
#15 0x00005557e475b033 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x2f5b033)
#16 0x00005557e475ce21 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, llvm::LoopInfo*) InstructionCombining.cpp:0:0
#17 0x00005557e475dce3 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x2f5dce3)
#18 0x00005557e5d77e61 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x4577e61)
#19 0x00005557e4530e4f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x2d30e4f)
#20 0x00005557e2c0d071 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x140d071)
#21 0x00005557e452f990 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x2d2f990)
#22 0x00005557e2c0d8f1 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x140d8f1)
#23 0x00005557e452caaa llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x2d2caaa)
#24 0x00005557e50a92d5 (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> >&) (.constprop.841) BackendUtil.cpp:0:0
#25 0x00005557e50abe19 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x38abe19)
#26 0x00005557e5d0592f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x450592f)
#27 0x00005557e6b9aa79 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x539aa79)
#28 0x00005557e5d05b02 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x4505b02)
#29 0x00005557e5701161 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3f01161)
#30 0x00005557e569c2f2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3e9c2f2)
#31 0x00005557e57cc853 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3fcc853)
#32 0x00005557e299b1d4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x119b1d4)
#33 0x00005557e299718d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#34 0x00005557e55375f5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x00005557e4cb7163 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x34b7163)
#36 0x00005557e55396c8 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3d396c8)
#37 0x00005557e550cb1a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3d0cb1a)
#38 0x00005557e550d65f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3d0d65f)
#39 0x00005557e5516005 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x3d16005)
#40 0x00005557e28a80b2 main (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x10a80b2)
#41 0x00007fb7ce040083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#42 0x00005557e2996d0a _start (/opt/compiler-explorer/clang-14.0.0/bin/clang+0x1196d0a)
clang-14: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltz2za3_TX0C0YaEhQvevCDLFtt-iVjn9htHzUgsC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