Fix multiple-return-value-to-first-class-aggregates autoupgrade to

correctly handle the case where multiple-return-value constructs
were used to return one or zero values.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53890 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-07-22 00:36:48 +00:00
parent 4e97401e1f
commit ceab39f0b7

View File

@ -420,12 +420,15 @@ void llvm::UpgradeCallsToIntrinsic(Function* F) {
/// function to use aggregate return values built with insertvalue
/// instructions.
void llvm::UpgradeMultipleReturnValues(Function *CurrentFunction) {
const Type *ReturnType = CurrentFunction->getReturnType();
for (Function::iterator I = CurrentFunction->begin(),
E = CurrentFunction->end(); I != E; ++I) {
BasicBlock *BB = I;
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
unsigned NumVals = RI->getNumOperands();
if (NumVals > 1) {
if (NumVals > 1 ||
(isa<StructType>(ReturnType) &&
(NumVals == 0 || RI->getOperand(0)->getType() != ReturnType))) {
std::vector<const Type *> Types(NumVals);
for (unsigned i = 0; i != NumVals; ++i)
Types[i] = RI->getOperand(i)->getType();