- assert(isa<StructType>(RetTy) && "Return type changed, but not into a"
- "void. The old return type must have"
- "been a struct!");
- // The original return value was a struct, update all uses (which are
- // all extractvalue instructions).
- for (Value::use_iterator I = Call->use_begin(), E = Call->use_end();
- I != E;) {
- assert(isa<ExtractValueInst>(*I) && "Return value not only used by"
- "extractvalue?");
- ExtractValueInst *EV = cast<ExtractValueInst>(*I);
- // Increment now, since we're about to throw away this use.
- ++I;
- assert(EV->hasIndices() && "Return value used by extractvalue without"
- "indices?");
- unsigned Idx = *EV->idx_begin();
- if (NewRetIdxs[Idx] != -1) {
- if (RetTypes.size() > 1) {
- // We're still returning a struct, create a new extractvalue
- // instruction with the first index updated
- std::vector<unsigned> NewIdxs(EV->idx_begin(), EV->idx_end());
- NewIdxs[0] = NewRetIdxs[Idx];
- Value *NEV = ExtractValueInst::Create(New, NewIdxs.begin(),
- NewIdxs.end(), "retval",
- EV);
- EV->replaceAllUsesWith(NEV);
- EV->eraseFromParent();
- } else {
- // We are now only returning a simple value, remove the
- // extractvalue
- EV->replaceAllUsesWith(New);
- EV->eraseFromParent();
- }
- } else {
- // Value unused, replace uses by null for now, they will get removed
- // later on
- EV->replaceAllUsesWith(Constant::getNullValue(EV->getType()));
- EV->eraseFromParent();
- }
+ assert(RetTy->isStructTy() &&
+ "Return type changed, but not into a void. The old return type"
+ " must have been a struct!");
+ Instruction *InsertPt = Call;
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
+ BasicBlock::iterator IP = II->getNormalDest()->begin();
+ while (isa<PHINode>(IP)) ++IP;
+ InsertPt = IP;