llvm.org GIT mirror llvm / fd42335
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218302 91177308-0d34-0410-b5e6-96231b3b80d8 Petar Jovanovic 4 years ago
2 changed file(s) with 25 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
33463346 assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
33473347
33483348 // Just forget the function body, we can remat it later.
3349 F->deleteBody();
3349 F->dropAllReferences();
33503350 }
33513351
33523352 std::error_code BitcodeReader::MaterializeModule(Module *M) {
5555 ErrorOr ModuleOrErr =
5656 getLazyBitcodeModule(std::move(Buffer), Context);
5757 return std::unique_ptr(ModuleOrErr.get());
58 }
59
60 TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) {
61 SmallString<1024> Mem;
62
63 LLVMContext Context;
64 std::unique_ptr M = getLazyModuleFromAssembly(
65 Context, Mem, "define internal i32 @func() {\n"
66 "ret i32 0\n"
67 "}\n");
68
69 EXPECT_FALSE(verifyModule(*M, &dbgs()));
70
71 M->getFunction("func")->Materialize();
72 EXPECT_FALSE(M->getFunction("func")->empty());
73 EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
74 GlobalValue::InternalLinkage);
75
76 // Check that the linkage type is preserved after dematerialization.
77 M->getFunction("func")->Dematerialize();
78 EXPECT_TRUE(M->getFunction("func")->empty());
79 EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
80 GlobalValue::InternalLinkage);
81 EXPECT_FALSE(verifyModule(*M, &dbgs()));
5882 }
5983
6084 TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677