llvm.org GIT mirror llvm / 37914c8
fix PR6305 by handling BlockAddress in a helper function called by jump threading. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96263 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
3 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
489489 // Splice all the instructions from PredBB to DestBB.
490490 PredBB->getTerminator()->eraseFromParent();
491491 DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
492
493 // Zap anything that took the address of DestBB. Not doing this will give the
494 // address an invalid value.
495 if (DestBB->hasAddressTaken()) {
496 BlockAddress *BA = BlockAddress::get(DestBB);
497 Constant *Replacement =
498 ConstantInt::get(llvm::Type::getInt32Ty(BA->getContext()), 1);
499 BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
500 BA->getType()));
501 BA->destroyConstant();
502 }
492503
493504 // Anything that branched to PredBB now branches to DestBB.
494505 PredBB->replaceAllUsesWith(DestBB);
88
99 define void @test(i32 %i) nounwind ssp {
1010 entry:
11 call void @test(i32 1)
1112 br label %foo
1213
13 foo: ; preds = %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto
14 foo:
15 call void @test(i32 1)
1416 br label %bar
1517
16 bar: ; preds = %foo, %indirectgoto
18 bar:
19 call void @test(i32 1)
1720 br label %hack
1821
19 hack: ; preds = %bar, %indirectgoto
22 hack:
23 call void @test(i32 1)
2024 ret void
2125 }
312312 for.body: ; preds = %for.cond
313313 br label %for.cond
314314 }
315
316
317 ; PR6305
318 define void @test11() nounwind {
319 entry:
320 br label %A
321
322 A: ; preds = %entry
323 call void undef(i64 ptrtoint (i8* blockaddress(@test11, %A) to i64)) nounwind
324 unreachable
325 }