LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 41595 - OrcJIT's MaterializationResponsibility fails asserts (also in KaleidoscopeJIT Ch2)
Summary: OrcJIT's MaterializationResponsibility fails asserts (also in KaleidoscopeJIT...
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: OrcJIT (show other bugs)
Version: 8.0
Hardware: PC Windows NT
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-24 18:32 PDT by Fabian Muehlboeck
Modified: 2019-04-24 18:39 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Muehlboeck 2019-04-24 18:32:48 PDT
Using OrcJIT in llvm 8.0.0 fails very quickly in an assert failure in MaterializationResponsibility::resolve, which seems to be internal to OrcJIT and out of the control of the user. Just running Kaleidoscope Ch2 as included in the source code distribution causes 

    assert(I != SymbolFlags.end() &&
           "Resolving symbol outside this responsibility set");

in lines 399 and 400 of ExecutionEngine/Orc/Core.cpp to fail. In particular, this seems to reliably happen after entering the second line code, say "5+2" and "5+2".

Originally, I just tried to compile a function that returns an integer constant and is marked as having external linkage, which failed in the same function at lines 407 and 408:

      assert(I->second == KV.second.getFlags() &&
             "Resolving symbol with incorrect flags");

As far as I can tell from the data, "I" has a Flags field whose value is "Exported | Callable (48 '0')", and "KV" has a Flags field whose value is just "Callable (32 '0')". After setting up a JIT much like in Kaleidoscope, the following is all that this code does to produce that error:

auto theModule = llvm::make_unique<llvm::Module>("module", LLVMCONTEXT);
theModule->setDataLayout(NomJIT::Instance()->getDataLayout());

llvm::Function *fun = llvm::Function::Create(llvm::FunctionType::get(INTTYPE, false), llvm::Function::ExternalLinkage, "testmethod", theModule.get());
	
BasicBlock *startBlock = BasicBlock::Create(LLVMCONTEXT, "testmethod$start", fun);

IRBuilder<> builder(LLVMCONTEXT);
builder.SetInsertPoint(startBlock);
builder.CreateRet(llvm::ConstantInt::get(INTTYPE, 5, true));
if (verifyFunction(*fun))
{
	throw "Failed verification";
}

MyJIT::Instance()->addModule(std::move(theModule));
auto MainSymbol = ExitOnErr(MyJIT::Instance()->lookup("testmethod")); //FAILS HERE
int (*mainmeth)() = (int (*)())(intptr_t)MainSymbol.getAddress();
std::cout<<mainmeth(); 


I'm running Windows 10 and compiled llvm (from the 8.0.0 source tar available on llvm.org) and the other projects with Visual Studio 2017, and the same problems happen on two different machines with the same setup.