getresult does not support nested aggregates.
authorDevang Patel <dpatel@apple.com>
Wed, 20 Feb 2008 19:39:41 +0000 (19:39 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 20 Feb 2008 19:39:41 +0000 (19:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47396 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Instructions.cpp

index c1e583375a2cc9a90856df9e20d08cd1cde0e4cf..4197f80c922a775e30adb6824dc79b4590e1435a 100644 (file)
@@ -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;
 }