@@ -513,21 +513,24 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
513
513
}
514
514
515
515
// Now that we've done the deed, simplify the switch instruction.
516
+ const Type *OldFnRetTy = TheSwitch->getParent ()->getParent ()->getReturnType ();
516
517
switch (NumExitBlocks) {
517
518
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
519
520
// means that previously this was the last part of the function, and hence
520
521
// this should be rewritten as a `ret'
521
522
522
523
// 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 ()) {
526
527
// return what we have
527
528
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
+ }
531
534
532
535
TheSwitch->getParent ()->getInstList ().erase (TheSwitch);
533
536
break ;
@@ -583,8 +586,8 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) {
583
586
// / for each scalar output in the function: at every exit, store intermediate
584
587
// / computed result back into memory.
585
588
// /
586
- Function *CodeExtractor::ExtractCodeRegion ( const std::vector<BasicBlock*> &code)
587
- {
589
+ Function *CodeExtractor::
590
+ ExtractCodeRegion ( const std::vector<BasicBlock*> &code) {
588
591
if (!isEligible (code))
589
592
return 0 ;
590
593
0 commit comments