Skip to content

Commit 0fe9bd9

Browse files
author
John Criswell
committed
Merged from mainline.
llvm-svn: 15686
1 parent 322e131 commit 0fe9bd9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

llvm/lib/Transforms/Hello/Hello.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/Pass.h"
1616
#include "llvm/Function.h"
17+
#include <iostream>
1718
using namespace llvm;
1819

1920
namespace {

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,21 +513,24 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
513513
}
514514

515515
// Now that we've done the deed, simplify the switch instruction.
516+
const Type *OldFnRetTy = TheSwitch->getParent()->getParent()->getReturnType();
516517
switch (NumExitBlocks) {
517518
case 0:
518-
// There is only 1 successor (the block containing the switch itself), which
519+
// There are no successors (the block containing the switch itself), which
519520
// means that previously this was the last part of the function, and hence
520521
// this should be rewritten as a `ret'
521522

522523
// Check if the function should return a value
523-
if (TheSwitch->getParent()->getParent()->getReturnType() != Type::VoidTy &&
524-
TheSwitch->getParent()->getParent()->getReturnType() ==
525-
TheSwitch->getCondition()->getType())
524+
if (OldFnRetTy == Type::VoidTy) {
525+
new ReturnInst(0, TheSwitch); // Return void
526+
} else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
526527
// return what we have
527528
new ReturnInst(TheSwitch->getCondition(), TheSwitch);
528-
else
529-
// just return
530-
new ReturnInst(0, TheSwitch);
529+
} else {
530+
// Otherwise we must have code extracted an unwind or something, just
531+
// return whatever we want.
532+
new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch);
533+
}
531534

532535
TheSwitch->getParent()->getInstList().erase(TheSwitch);
533536
break;
@@ -583,8 +586,8 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) {
583586
/// for each scalar output in the function: at every exit, store intermediate
584587
/// computed result back into memory.
585588
///
586-
Function *CodeExtractor::ExtractCodeRegion(const std::vector<BasicBlock*> &code)
587-
{
589+
Function *CodeExtractor::
590+
ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
588591
if (!isEligible(code))
589592
return 0;
590593

0 commit comments

Comments
 (0)