diff options
author | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2014-09-23 12:54:19 +0000 |
---|---|---|
committer | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2014-09-23 12:54:19 +0000 |
commit | 7480e4db5e629e8410c9fed37b3f9a16bb57a8fa (patch) | |
tree | c08583030536877e89eae4c00a76e68ad87ca6e0 /llvm/unittests/Bitcode/BitReaderTest.cpp | |
parent | 40592d2dec009c2bb3204c75d195f42ebcada739 (diff) | |
download | llvm-7480e4db5e629e8410c9fed37b3f9a16bb57a8fa.zip llvm-7480e4db5e629e8410c9fed37b3f9a16bb57a8fa.tar.gz llvm-7480e4db5e629e8410c9fed37b3f9a16bb57a8fa.tar.bz2 |
Do not destroy external linkage when deleting function body
The function deleteBody() converts the linkage to external and thus destroys
original linkage type value. Lack of correct linkage type causes wrong
relocations to be emitted later.
Calling dropAllReferences() instead of deleteBody() will fix the issue.
Differential Revision: http://reviews.llvm.org/D5415
llvm-svn: 218302
Diffstat (limited to 'llvm/unittests/Bitcode/BitReaderTest.cpp')
-rw-r--r-- | llvm/unittests/Bitcode/BitReaderTest.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/unittests/Bitcode/BitReaderTest.cpp b/llvm/unittests/Bitcode/BitReaderTest.cpp index a27332b..04c7950 100644 --- a/llvm/unittests/Bitcode/BitReaderTest.cpp +++ b/llvm/unittests/Bitcode/BitReaderTest.cpp @@ -58,6 +58,30 @@ static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context, return std::unique_ptr<Module>(ModuleOrErr.get()); } +TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) { + SmallString<1024> Mem; + + LLVMContext Context; + std::unique_ptr<Module> M = getLazyModuleFromAssembly( + Context, Mem, "define internal i32 @func() {\n" + "ret i32 0\n" + "}\n"); + + EXPECT_FALSE(verifyModule(*M, &dbgs())); + + M->getFunction("func")->Materialize(); + EXPECT_FALSE(M->getFunction("func")->empty()); + EXPECT_TRUE(M->getFunction("func")->getLinkage() == + GlobalValue::InternalLinkage); + + // Check that the linkage type is preserved after dematerialization. + M->getFunction("func")->Dematerialize(); + EXPECT_TRUE(M->getFunction("func")->empty()); + EXPECT_TRUE(M->getFunction("func")->getLinkage() == + GlobalValue::InternalLinkage); + EXPECT_FALSE(verifyModule(*M, &dbgs())); +} + TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677 SmallString<1024> Mem; |