[llvm] r218302 - Do not destroy external linkage when deleting function body
Petar Jovanovic
petar.jovanovic at imgtec.com
Tue Sep 23 05:54:19 PDT 2014
Author: petarj
Date: Tue Sep 23 07:54:19 2014
New Revision: 218302
URL: http://llvm.org/viewvc/llvm-project?rev=218302&view=rev
Log:
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
Modified:
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/unittests/Bitcode/BitReaderTest.cpp
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=218302&r1=218301&r2=218302&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Sep 23 07:54:19 2014
@@ -3347,7 +3347,7 @@ void BitcodeReader::Dematerialize(Global
assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
// Just forget the function body, we can remat it later.
- F->deleteBody();
+ F->dropAllReferences();
}
std::error_code BitcodeReader::MaterializeModule(Module *M) {
Modified: llvm/trunk/unittests/Bitcode/BitReaderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitReaderTest.cpp?rev=218302&r1=218301&r2=218302&view=diff
==============================================================================
--- llvm/trunk/unittests/Bitcode/BitReaderTest.cpp (original)
+++ llvm/trunk/unittests/Bitcode/BitReaderTest.cpp Tue Sep 23 07:54:19 2014
@@ -58,6 +58,30 @@ static std::unique_ptr<Module> getLazyMo
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;
More information about the llvm-commits
mailing list