Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -5440,7 +5440,19 @@ bool InBounds = EatIfPresent(lltok::kw_inbounds); - if (ParseTypeAndValue(Ptr, Loc, PFS)) return true; + Type *Ty = nullptr; + LocTy ExplicitTypeLoc = Lex.getLoc(); + if (ParseType(Ty) || + ParseToken(lltok::comma, "expected comma after getelementptr's type") || + ParseTypeAndValue(Ptr, Loc, PFS)) + return true; + + Type *PtrTy = Ptr->getType(); + if (VectorType *VT = dyn_cast(PtrTy)) + PtrTy = VT->getElementType(); + if (Ty != cast(PtrTy)->getElementType()) + return Error(ExplicitTypeLoc, + "explicit pointee type doesn't match operand's pointee type"); Type *BaseType = Ptr->getType(); PointerType *BasePointerType = dyn_cast(BaseType->getScalarType()); Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -2898,6 +2898,11 @@ Out << ", "; TypePrinter.print(I.getType(), Out); } else if (Operand) { // Print the normal way. + if (const GetElementPtrInst *GEP = dyn_cast(&I)) { + Out << ' '; + TypePrinter.print(GEP->getSourceElementType(), Out); + Out << ','; + } // PrintAllTypes - Instructions who have operands of all the same type // omit the type from all but the first operand. If the instruction has Index: test/Assembler/invalid-gep-mismatched-explicit-type.ll =================================================================== --- /dev/null +++ test/Assembler/invalid-gep-mismatched-explicit-type.ll @@ -0,0 +1,6 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +; CHECK: :4:22: error: explicit pointee type doesn't match operand's pointee type +define void @test(i32* %t) { + %x = getelementptr i16, i32* %t, i32 0 + ret void +} Index: test/Assembler/invalid-gep-missing-explicit-type.ll =================================================================== --- /dev/null +++ test/Assembler/invalid-gep-missing-explicit-type.ll @@ -0,0 +1,7 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +; CHECK: :4:27: error: expected comma after getelementptr's type +define void @test(i32* %t) { + %x = getelementptr i32* %t, i32 0 + ret void +} + Index: unittests/IR/ConstantsTest.cpp =================================================================== --- unittests/IR/ConstantsTest.cpp +++ unittests/IR/ConstantsTest.cpp @@ -248,9 +248,9 @@ // FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP, // not a normal one! //CHECK(ConstantExpr::getGetElementPtr(Global, V, false), - // "getelementptr i32** @dummy, i32 1"); + // "getelementptr i32*, i32** @dummy, i32 1"); CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V), - "getelementptr inbounds i32** @dummy, i32 1"); + "getelementptr inbounds i32*, i32** @dummy, i32 1"); CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> " P6STR ", i32 1");