LLParser: gep: Simplify parsing error handling
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 9 Mar 2015 23:08:44 +0000 (23:08 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 9 Mar 2015 23:08:44 +0000 (23:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231722 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
test/Assembler/getelementptr_invalid_ptr.ll

index 67d74c0c121fede231d93c4feb9eb8581dd6a8c7..65e622af66c372ea9419a95cd18df7af36388fa9 100644 (file)
@@ -5465,21 +5465,15 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
       ParseTypeAndValue(Ptr, Loc, PFS))
     return true;
 
-  Type *PtrTy = Ptr->getType();
-  if (VectorType *VT = dyn_cast<VectorType>(PtrTy))
-    PtrTy = VT->getElementType();
-  SequentialType *SeqPtrTy = dyn_cast<SequentialType>(PtrTy);
-  if (!SeqPtrTy)
-    return Error(Loc, "pointer type is not valid");
-  if (Ty != SeqPtrTy->getElementType())
-    return Error(ExplicitTypeLoc,
-                 "explicit pointee type doesn't match operand's pointee type");
-
   Type *BaseType = Ptr->getType();
   PointerType *BasePointerType = dyn_cast<PointerType>(BaseType->getScalarType());
   if (!BasePointerType)
     return Error(Loc, "base of getelementptr must be a pointer");
 
+  if (Ty != BasePointerType->getElementType())
+    return Error(ExplicitTypeLoc,
+                 "explicit pointee type doesn't match operand's pointee type");
+
   SmallVector<Value*, 16> Indices;
   bool AteExtraComma = false;
   while (EatIfPresent(lltok::comma)) {
index ff12debc1bc39edcbb24986382542f49cdcc4d92..892292729a1883baf04de1b61e1e6f3fd691646a 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
 ; Test the case of an invalid pointer type on a GEP
 
-; CHECK: pointer type is not valid
+; CHECK: base of getelementptr must be a pointer
 
 define i32* @foo(i32 %a) {
   %gep = getelementptr i32, i32 %a, i32 1