aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VMCore/Instructions.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index c1e583375a..4197f80c92 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -2719,10 +2719,21 @@ GetResultInst::GetResultInst(Value *Aggregate, unsigned Index,
bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) {
if (!Aggregate)
return false;
- if (const StructType *STy = dyn_cast<StructType>(Aggregate->getType()))
- if (Index < STy->getNumElements())
- return true;
+ if (const StructType *STy = dyn_cast<StructType>(Aggregate->getType())) {
+ unsigned NumElements = STy->getNumElements();
+ if (Index >= NumElements)
+ return false;
+
+ // getresult aggregate value's element types are restricted to
+ // avoid nested aggregates.
+ for (unsigned i = 0; i < NumElements; ++i)
+ if (!STy->getElementType(i)->isFirstClassType())
+ return false;
+
+ // Otherwise, Aggregate is valid.
+ return true;
+ }
return false;
}