diff options
author | Lang Hames <lhames@gmail.com> | 2018-06-14 21:16:29 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2018-06-14 21:16:29 +0000 |
commit | 5d6c509944fc2a5873d0a70410c82a6ebd4ae31c (patch) | |
tree | d3ecf5ca8d6103d015eec13cc7f80e5fa905f974 /llvm/unittests/ExecutionEngine | |
parent | 248acf6b57ecb38125aed1ea1d7d547d99e4100f (diff) | |
download | bcm5719-llvm-5d6c509944fc2a5873d0a70410c82a6ebd4ae31c.tar.gz bcm5719-llvm-5d6c509944fc2a5873d0a70410c82a6ebd4ae31c.zip |
[ORC] Strip weak flags from a symbol once it is selected for materialization.
Once a symbol has been selected for materialization it can no longer be
overridden. Stripping the weak flag guarantees this (override attempts will
then be treated as duplicate definitions and result in a DuplicateDefinition
error).
llvm-svn: 334771
Diffstat (limited to 'llvm/unittests/ExecutionEngine')
-rw-r--r-- | llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp index c8f30dbfd94..589cdb4d745 100644 --- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp @@ -10,6 +10,7 @@ #include "OrcTestCommon.h" #include "llvm/Config/llvm-config.h" #include "llvm/ExecutionEngine/Orc/Core.h" +#include "llvm/ExecutionEngine/Orc/OrcError.h" #include "gtest/gtest.h" #include <set> @@ -768,4 +769,50 @@ TEST(CoreAPIsTest, TestGetRequestedSymbolsAndDelegate) { EXPECT_TRUE(BarMaterialized) << "Bar should be materialized now"; } +TEST(CoreAPIsTest, TestMaterializeWeakSymbol) { + // Confirm that once a weak definition is selected for materialization it is + // treated as strong. + + constexpr JITTargetAddress FakeFooAddr = 0xdeadbeef; + JITSymbolFlags FooFlags = JITSymbolFlags::Exported; + FooFlags &= JITSymbolFlags::Weak; + auto FooSym = JITEvaluatedSymbol(FakeFooAddr, FooFlags); + + ExecutionSession ES; + auto Foo = ES.getSymbolStringPool().intern("foo"); + + auto &V = ES.createVSO("V"); + + std::unique_ptr<MaterializationResponsibility> FooResponsibility; + auto MU = llvm::make_unique<SimpleMaterializationUnit>( + SymbolFlagsMap({{Foo, FooFlags}}), [&](MaterializationResponsibility R) { + FooResponsibility = + llvm::make_unique<MaterializationResponsibility>(std::move(R)); + }); + + cantFail(V.define(MU)); + auto Q = std::make_shared<AsynchronousSymbolQuery>( + SymbolNameSet({Foo}), + [](Expected<AsynchronousSymbolQuery::ResolutionResult> R) { + cantFail(std::move(R)); + }, + [](Error Err) { cantFail(std::move(Err)); }); + V.lookup(std::move(Q), SymbolNameSet({Foo})); + + auto MU2 = llvm::make_unique<SimpleMaterializationUnit>( + SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}}), + [](MaterializationResponsibility R) { + llvm_unreachable("This unit should never be materialized"); + }); + + auto Err = V.define(MU2); + EXPECT_TRUE(!!Err) << "Expected failure value"; + EXPECT_TRUE(Err.isA<DuplicateDefinition>()) + << "Expected a duplicate definition error"; + consumeError(std::move(Err)); + + FooResponsibility->resolve(SymbolMap({{Foo, FooSym}})); + FooResponsibility->finalize(); +} + } // namespace |