Fix for PR#330.
[oota-llvm.git] / lib / VMCore / iMemory.cpp
index 1fc1df8c95bffb6bc9e3ef8f14e0594092e3b67e..32fe71a08626533af70bbacfc9ef03465fbb62ab 100644 (file)
@@ -156,6 +156,14 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
       return 0;  // Can only index into pointer types at the first index!
     if (!CT->indexValid(Index)) return 0;
     Ptr = CT->getTypeAtIndex(Index);
+
+    // If the new type forwards to another type, then it is in the middle
+    // of being refined to another type (and hence, may have dropped all
+    // references to what it was using before).  So, use the new forwarded
+    // type.
+    if (Ptr->getForwardedType()) {
+      Ptr = Ptr->getForwardedType();
+    }
   }
   return CurIdx == Idx.size() ? Ptr : 0;
 }