[llvm] r180030 - Fix for PR 14965: Better error message for GEP with partially defined contents

Eli Bendersky eliben at google.com
Mon Apr 22 10:03:42 PDT 2013


Author: eliben
Date: Mon Apr 22 12:03:42 2013
New Revision: 180030

URL: http://llvm.org/viewvc/llvm-project?rev=180030&view=rev
Log:
Fix for PR 14965: Better error message for GEP with partially defined contents

Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=180030&r1=180029&r2=180030&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Apr 22 12:03:42 2013
@@ -4263,7 +4263,9 @@ int LLParser::ParseGetElementPtr(Instruc
 
   if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;
 
-  if (!Ptr->getType()->getScalarType()->isPointerTy())
+  Type *BaseType = Ptr->getType();
+  PointerType *BasePointerType = dyn_cast<PointerType>(BaseType->getScalarType());
+  if (!BasePointerType)
     return Error(Loc, "base of getelementptr must be a pointer");
 
   SmallVector<Value*, 16> Indices;
@@ -4288,7 +4290,10 @@ int LLParser::ParseGetElementPtr(Instruc
     Indices.push_back(Val);
   }
 
-  if (!GetElementPtrInst::getIndexedType(Ptr->getType(), Indices))
+  if (!Indices.empty() && !BasePointerType->getElementType()->isSized())
+    return Error(Loc, "base element of getelementptr must be sized");
+
+  if (!GetElementPtrInst::getIndexedType(BaseType, Indices))
     return Error(Loc, "invalid getelementptr indices");
   Inst = GetElementPtrInst::Create(Ptr, Indices);
   if (InBounds)





More information about the llvm-commits mailing list