summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-12 03:17:02 +0000
committerChris Lattner <sabre@nondot.org>2004-08-12 03:17:02 +0000
commitb519efbafedb356a30a04a32c15a6b406779a997 (patch)
tree14104c18ef12629b168a432ea07feab104178bf7 /lib/Transforms
parentcc6b01b1e68cd87807f94a8c51088be9ff096e71 (diff)
downloadllvm-b519efbafedb356a30a04a32c15a6b406779a997.tar.gz
llvm-b519efbafedb356a30a04a32c15a6b406779a997.tar.bz2
llvm-b519efbafedb356a30a04a32c15a6b406779a997.tar.xz
Fix code extraction of unwind blocks. This fixed bugs that bugpoint can
run into. This should go into 1.3 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15679 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index dbc358bf61..b3de38a5db 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -513,21 +513,24 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
}
// Now that we've done the deed, simplify the switch instruction.
+ const Type *OldFnRetTy = TheSwitch->getParent()->getParent()->getReturnType();
switch (NumExitBlocks) {
case 0:
- // There is only 1 successor (the block containing the switch itself), which
+ // There are no successors (the block containing the switch itself), which
// means that previously this was the last part of the function, and hence
// this should be rewritten as a `ret'
// Check if the function should return a value
- if (TheSwitch->getParent()->getParent()->getReturnType() != Type::VoidTy &&
- TheSwitch->getParent()->getParent()->getReturnType() ==
- TheSwitch->getCondition()->getType())
+ if (OldFnRetTy == Type::VoidTy) {
+ new ReturnInst(0, TheSwitch); // Return void
+ } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
// return what we have
new ReturnInst(TheSwitch->getCondition(), TheSwitch);
- else
- // just return
- new ReturnInst(0, TheSwitch);
+ } else {
+ // Otherwise we must have code extracted an unwind or something, just
+ // return whatever we want.
+ new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch);
+ }
TheSwitch->getParent()->getInstList().erase(TheSwitch);
break;
@@ -583,8 +586,8 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) {
/// for each scalar output in the function: at every exit, store intermediate
/// computed result back into memory.
///
-Function *CodeExtractor::ExtractCodeRegion(const std::vector<BasicBlock*> &code)
-{
+Function *CodeExtractor::
+ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
if (!isEligible(code))
return 0;