Fix a crash in the LL parser where it failed to validate that the pointer operand...
authorOwen Anderson <resistor@mac.com>
Mon, 2 Mar 2015 05:25:06 +0000 (05:25 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 2 Mar 2015 05:25:06 +0000 (05:25 +0000)
This manifested as an assertion failure in +Asserts builds, and a hard crash in -Asserts builds.  Found by fuzzing the LL parser.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230934 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
test/Assembler/getelementptr_invalid_ptr.ll [new file with mode: 0644]

index 40563b536bde547867018a4f05dd7adc1a28bb9c..d50da69529ce5a5f014025e6dcf7251f98d17eb7 100644 (file)
@@ -5458,6 +5458,8 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
     return true;
 
   Type *PtrTy = Ptr->getType();
+  if (!isa<SequentialType>(PtrTy))
+    return Error(Loc, "pointer type is not valid");
   if (VectorType *VT = dyn_cast<VectorType>(PtrTy))
     PtrTy = VT->getElementType();
   if (Ty != cast<SequentialType>(PtrTy)->getElementType())
diff --git a/test/Assembler/getelementptr_invalid_ptr.ll b/test/Assembler/getelementptr_invalid_ptr.ll
new file mode 100644 (file)
index 0000000..8296dd3
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: not llvm-as < %s >/dev/null 2> %t
+; RUN: FileCheck %s < %t
+; Test the case of an invalid pointer type on a GEP
+
+; CHECK: pointer type is not valid
+
+define i32* @foo(i32 %a) {
+  %gep = getelementptr i32, i32 %a, i32 1
+  return i32* %gep
+}
+