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.

llvm-svn: 53890
This commit is contained in:
Dan Gohman 2008-07-22 00:36:48 +00:00
parent d07cee2e5c
commit cf971f0513
1 changed files with 4 additions and 1 deletions

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();