llvm.org GIT mirror llvm / 122f5e5
BitcodeReader: Correctly insert blockaddress constant referring to a already parsed function. We inserted a placeholder that was never replaced because the function was already visited. Assert that all placeholders have been resolved when tearing down the bitcode reader. Fixes PR13895. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164369 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
2 changed file(s) with 37 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
5151 std::vector().swap(FunctionsWithBodies);
5252 DeferredFunctionInfo.clear();
5353 MDKindMap.clear();
54
55 assert(BlockAddrFwdRefs.empty() && "Unresolved blockaddress fwd references");
5456 }
5557
5658 //===----------------------------------------------------------------------===//
12991301 Function *Fn =
13001302 dyn_cast_or_null(ValueList.getConstantFwdRef(Record[1],FnTy));
13011303 if (Fn == 0) return Error("Invalid CE_BLOCKADDRESS record");
1302
1303 GlobalVariable *FwdRef = new GlobalVariable(*Fn->getParent(),
1304 Type::getInt8Ty(Context),
1304
1305 // If the function is already parsed we can insert the block address right
1306 // away.
1307 if (!Fn->empty()) {
1308 Function::iterator BBI = Fn->begin(), BBE = Fn->end();
1309 for (size_t I = 0, E = Record[2]; I != E; ++I) {
1310 if (BBI == BBE)
1311 return Error("Invalid blockaddress block #");
1312 ++BBI;
1313 }
1314 V = BlockAddress::get(Fn, BBI);
1315 } else {
1316 // Otherwise insert a placeholder and remember it so it can be inserted
1317 // when the function is parsed.
1318 GlobalVariable *FwdRef = new GlobalVariable(*Fn->getParent(),
1319 Type::getInt8Ty(Context),
13051320 false, GlobalValue::InternalLinkage,
1306 0, "");
1307 BlockAddrFwdRefs[Fn].push_back(std::make_pair(Record[2], FwdRef));
1308 V = FwdRef;
1321 0, "");
1322 BlockAddrFwdRefs[Fn].push_back(std::make_pair(Record[2], FwdRef));
1323 V = FwdRef;
1324 }
13091325 break;
13101326 }
13111327 }
2727 end:
2828 ret void
2929 }
30
31 ; PR13895
32 define void @doitagain(i8** nocapture %pptr) {
33 ; CHECK: define void @doitagain
34 entry:
35 br label %here
36
37 here:
38 store i8* blockaddress(@doit, %here), i8** %pptr, align 8
39 ; CHECK: blockaddress(@doit, %here)
40 br label %end
41
42 end:
43 ret void
44 }