<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115339>115339</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
JIT compilation does not terminate
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pascalginter
</td>
</tr>
</table>
<pre>
I am trying to jit compile C++ code using libclang. I am mostly following this tutorial https://blog.memzero.de/llvm-orc-jit/ with some modifications to support C++ instead of C and linking the standard library.
My approach works fine for some cases but encounters issues when calling insert on an unordered map. The encountered issue is that a lookup with the mangled function name does not terminate as the compilation of the generated llvm code seems to happen lazily and gets stuck. There is no error message, simply what seems like an endless loop/deadlock.
A minimal example to produce the issue is jit compiling the following code:
Note that it works when replacing unordered_map with map. The code the gets compiled and can be executed.
```cpp
#include <unordered_map>
#include <iostream>
void* __dso_handle = (void*) &__dso_handle;
void std::__libcpp_verbose_abort(char const* format, ...) noexcept {std::abort();}"
void jitted(){\n"
std::unordered_map<int, int> map;"
map.insert({2, 3});"
std::cout << map[2] << std::endl;
}
```
Curiously I managed to get a more complicated example working with unordered_map<tuple<char>, tuple<int32_t>> insert but did not manage to produce a simple working version.
Stack trace when interrupting execution
```
0x0000555557340fd3 in bool llvm::DenseMapBase<llvm::DenseMap<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> >, llvm::DenseMapInfo<llvm::APFloat, void>, llvm::detail::DenseMapPair<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> > > >, llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> >, llvm::DenseMapInfo<llvm::APFloat, void>, llvm::detail::DenseMapPair<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> > > >::LookupBucketFor<llvm::APFloat>(llvm::APFloat const&, llvm::detail::DenseMapPair<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> > >*&) ()
(gdb) where
#0 0x0000555557340fd3 in bool llvm::DenseMapBase<llvm::DenseMap<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> >, llvm::DenseMapInfo<llvm::APFloat, void>, llvm::detail::DenseMapPair<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> > > >, llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> >, llvm::DenseMapInfo<llvm::APFloat, void>, llvm::detail::DenseMapPair<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> > > >::LookupBucketFor<llvm::APFloat>(llvm::APFloat const&, llvm::detail::DenseMapPair<llvm::APFloat, std::unique_ptr<llvm::ConstantFP, std::default_delete<llvm::ConstantFP> > >*&) ()
#1 0x0000555557343f10 in llvm::ConstantFP::get(llvm::LLVMContext&, llvm::APFloat const&) ()
#2 0x000055555627b0e4 in llvm::SelectionDAG::getConstantFP(llvm::APFloat const&, llvm::SDLoc const&, llvm::EVT, bool) ()
#3 0x0000555556270031 in llvm::SelectionDAG::FoldConstantArithmetic(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::ArrayRef<llvm::SDValue>, llvm::SDNodeFlags) ()
#4 0x0000555556273cd6 in llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) ()
#5 0x0000555555b781d6 in llvm::X86TargetLowering::LowerFP_TO_INT(llvm::SDValue, llvm::SelectionDAG&) const ()
#6 0x00005555561c6f2e in (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) ()
#7 0x00005555561ca086 in llvm::SelectionDAG::Legalize() ()
#8 0x00005555562ab4fa in llvm::SelectionDAGISel::CodeGenAndEmitDAG() ()
#9 0x00005555562adeea in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) ()
#10 0x00005555562afb74 in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) ()
#11 0x000055555629eb29 in llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) ()
#12 0x000055555656281c in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) [clone .part.0] ()
#13 0x0000555557438c31 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
#14 0x0000555557438dc4 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
#15 0x0000555557437f5f in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
#16 0x0000555555d7c896 in llvm::orc::SimpleCompiler::operator()(llvm::Module&) ()
#17 0x0000555555d7cd1e in llvm::orc::ConcurrentIRCompiler::operator()(llvm::Module&) ()
#18 0x0000555555dbfa43 in llvm::orc::IRCompileLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility> >, llvm::orc::ThreadSafeModule) ()
#19 0x0000555555dc376c in llvm::orc::BasicIRLayerMaterializationUnit::materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility> >) ()
#20 0x0000555555d99b8a in llvm::orc::MaterializationTask::run() ()
#21 0x0000555555d9a182 in llvm::orc::ExecutionSession::dispatchOutstandingMUs() ()
#22 0x0000555555d9a54a in llvm::orc::ExecutionSession::OL_completeLookup(std::unique_ptr<llvm::orc::InProgressLookupState, std::default_delete<llvm::orc::InProgressLookupState> >, std::shared_ptr<llvm::orc::AsynchronousSymbolQuery>, std::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > const&)>) ()
#23 0x0000555555d9b8f2 in llvm::orc::InProgressFullLookupState::complete(std::unique_ptr<llvm::orc::InProgressLookupState, std::default_delete<llvm::orc::InProgressLookupState> >) ()
#24 0x0000555555d9dd82 in llvm::orc::ExecutionSession::OL_applyQueryPhase1(std::unique_ptr<llvm::orc::InProgressLookupState, std::default_delete<llvm::orc::InProgressLookupState> >, llvm::Error) ()
#25 0x0000555555d9e3f9 in llvm::orc::ExecutionSession::lookup(llvm::orc::LookupKind, std::vector<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::allocator<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags> > > const&, llvm::orc::SymbolLookupSet, llvm::orc::SymbolState, llvm::unique_function<void (llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef> > >)>, std::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > const&)>) ()
#26 0x0000555555d9e63d in llvm::orc::ExecutionSession::lookup(std::vector<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::allocator<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags> > > const&, llvm::orc::SymbolLookupSet, llvm::orc::LookupKind, llvm::orc::SymbolState, std::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > const&)>) ()
#27 0x0000555555d9f2a5 in llvm::orc::ExecutionSession::lookup(std::vector<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::allocator<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags> > > const&, llvm::orc::SymbolStringPtr, llvm::orc::SymbolState) ()
#28 0x0000555555d9f4a5 in llvm::orc::ExecutionSession::lookup(llvm::ArrayRef<llvm::orc::JITDylib*>, llvm::orc::SymbolStringPtr, llvm::orc::SymbolState)
```
I can provide the entire code of the toy project if beneficial.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWllz67YV_jX0CyYaLlqoBz1osTJK7di9cjJ904DAoYRrEGAB0Lby6zsAKUqkKC-3bns740zijEHgfN_5zkICBtaabQXAxBvMvMHiChdmJ9Ukx5pgvmXCgLpKJN1PVghnyKg9E1tkJPrODCIyyxkHNPfCmRfOEJEUUKHtDM4SwrHY9pBbl0lt-B6lknP57CzsmEamMFIxzNHOmFx70dQLl164TLjc9jLI_gIlexS8cMn5U_aLVOSX78x44RI9M7NDWmaAMklZygg2TApteekiz6UyNScmtAFMkUzRHGFBEWfisWQASBssKFZ2MFFY7Xuev_D8afnzdo9wniuJyQ49S_WoUcoEoFSqEppgDRolhUEgiCysUhoxrQvQ6HkHAhHMuUViQoMySAqEBSqEVBQUUJThvIcednBcDrRcj6w2O2wQRlzKxyIvHbaMMyy2HChKC0Gsz0jgDBCVoJGQBhlQGRPYAMLazS9D5OSxEtihLQhQ2ABFVtYyaBogc_LtcJ6DQBz_xfje6bUFo5E2BXl0bJVjJyQCpaRCGWiNt-CFc6RZlvM9erbES3ucPYL1GQTloLV1JvfCJQVMuSSPDbWnKGOCZZgjeMFZzsGyyZWkBQFHu1bm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