Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Differential D70259 Diff 230140 llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp
Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp
Show All 31 Lines | if (!LCTM) { | ||||
consumeError(LCTM.takeError()); | consumeError(LCTM.takeError()); | ||||
return; | return; | ||||
} | } | ||||
auto DummyTarget = ES.intern("DummyTarget"); | auto DummyTarget = ES.intern("DummyTarget"); | ||||
bool DummyTargetMaterialized = false; | bool DummyTargetMaterialized = false; | ||||
cantFail(JD.define(std::make_unique<SimpleMaterializationUnit>( | llvm_cantFail(JD.define(std::make_unique<SimpleMaterializationUnit>( | ||||
SymbolFlagsMap({{DummyTarget, JITSymbolFlags::Exported}}), | SymbolFlagsMap({{DummyTarget, JITSymbolFlags::Exported}}), | ||||
[&](MaterializationResponsibility R) { | [&](MaterializationResponsibility R) { | ||||
DummyTargetMaterialized = true; | DummyTargetMaterialized = true; | ||||
// No dependencies registered, can't fail. | // No dependencies registered, can't fail. | ||||
cantFail(R.notifyResolved( | llvm_cantFail(R.notifyResolved( | ||||
{{DummyTarget, | {{DummyTarget, | ||||
JITEvaluatedSymbol(static_cast<JITTargetAddress>( | JITEvaluatedSymbol(static_cast<JITTargetAddress>( | ||||
reinterpret_cast<uintptr_t>(&dummyTarget)), | reinterpret_cast<uintptr_t>(&dummyTarget)), | ||||
JITSymbolFlags::Exported)}})); | JITSymbolFlags::Exported)}})); | ||||
cantFail(R.notifyEmitted()); | llvm_cantFail(R.notifyEmitted()); | ||||
}))); | }))); | ||||
unsigned NotifyResolvedCount = 0; | unsigned NotifyResolvedCount = 0; | ||||
auto NotifyResolved = LazyCallThroughManager::createNotifyResolvedFunction( | auto NotifyResolved = LazyCallThroughManager::createNotifyResolvedFunction( | ||||
[&](JITDylib &JD, const SymbolStringPtr &SymbolName, | [&](JITDylib &JD, const SymbolStringPtr &SymbolName, | ||||
JITTargetAddress ResolvedAddr) { | JITTargetAddress ResolvedAddr) { | ||||
++NotifyResolvedCount; | ++NotifyResolvedCount; | ||||
return Error::success(); | return Error::success(); | ||||
}); | }); | ||||
auto CallThroughTrampoline = cantFail((*LCTM)->getCallThroughTrampoline( | auto CallThroughTrampoline = llvm_cantFail((*LCTM)->getCallThroughTrampoline( | ||||
JD, DummyTarget, std::move(NotifyResolved))); | JD, DummyTarget, std::move(NotifyResolved))); | ||||
auto CTTPtr = reinterpret_cast<int (*)()>( | auto CTTPtr = reinterpret_cast<int (*)()>( | ||||
static_cast<uintptr_t>(CallThroughTrampoline)); | static_cast<uintptr_t>(CallThroughTrampoline)); | ||||
// Call twice to verify nothing unexpected happens on redundant calls. | // Call twice to verify nothing unexpected happens on redundant calls. | ||||
auto Result = CTTPtr(); | auto Result = CTTPtr(); | ||||
(void)CTTPtr(); | (void)CTTPtr(); | ||||
EXPECT_TRUE(DummyTargetMaterialized) | EXPECT_TRUE(DummyTargetMaterialized) | ||||
<< "CallThrough did not materialize target"; | << "CallThrough did not materialize target"; | ||||
EXPECT_EQ(NotifyResolvedCount, 1U) | EXPECT_EQ(NotifyResolvedCount, 1U) | ||||
<< "CallThrough should have generated exactly one 'NotifyResolved' call"; | << "CallThrough should have generated exactly one 'NotifyResolved' call"; | ||||
EXPECT_EQ(Result, 42) << "Failed to call through to target"; | EXPECT_EQ(Result, 42) << "Failed to call through to target"; | ||||
} | } |