From 6d57086129102cde3c4bec03a09ab0e358ee5af5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 14 Jan 2003 22:19:44 +0000 Subject: [PATCH] Fix bug Regression/Verifier/2002-11-05-GetelementptrPointers.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5273 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Verifier.cpp | 1 - lib/VMCore/iMemory.cpp | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 145a66caf53..e156692ee8e 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -23,7 +23,6 @@ // * All Instructions must be embeded into a basic block // . Function's cannot take a void typed parameter // * Verify that a function's argument list agrees with it's declared type. -// . Verify that arrays and structures have fixed elements: No unsized arrays. // * It is illegal to specify a name for a void value. // * It is illegal to have a internal global value with no intitalizer // * It is illegal to have a ret instruction that returns a value that does not diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp index dacb8fe2a23..db9b9617a20 100644 --- a/lib/VMCore/iMemory.cpp +++ b/lib/VMCore/iMemory.cpp @@ -116,16 +116,18 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, // Handle the special case of the empty set index set... if (Idx.empty()) return cast(Ptr)->getElementType(); - unsigned CurIDX = 0; + unsigned CurIdx = 0; while (const CompositeType *CT = dyn_cast(Ptr)) { - if (Idx.size() == CurIDX) { + if (Idx.size() == CurIdx) { if (AllowCompositeLeaf || CT->isFirstClassType()) return Ptr; return 0; // Can't load a whole structure or array!?!? } - Value *Index = Idx[CurIDX++]; + Value *Index = Idx[CurIdx++]; + if (isa(CT) && CurIdx != 1) + return 0; // Can only index into pointer types at the first index! if (!CT->indexValid(Index)) return 0; Ptr = CT->getTypeAtIndex(Index); } - return CurIDX == Idx.size() ? Ptr : 0; + return CurIdx == Idx.size() ? Ptr : 0; }