[PATCH] [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Feb 26 23:39:47 PST 2015


LGTM.

> On 2015 Feb 26, at 16:14, David Blaikie <dblaikie at gmail.com> wrote:
> 
> rebase, add/improve error handling and test error cases
> 
> 
> http://reviews.llvm.org/D7636
> 
> Files:
>  lib/AsmParser/LLParser.cpp
>  lib/IR/AsmWriter.cpp
>  test/Assembler/invalid-gep-mismatched-explicit-type.ll
>  test/Assembler/invalid-gep-missing-explicit-type.ll
>  unittests/IR/ConstantsTest.cpp
> 
> 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<VectorType>(PtrTy))
> +    PtrTy = VT->getElementType();
> +  if (Ty != cast<SequentialType>(PtrTy)->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());
> 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<GetElementPtrInst>(&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: <stdin>: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: <stdin>: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");
> 
> EMAIL PREFERENCES
>  http://reviews.llvm.org/settings/panel/emailpreferences/
> <D7636.20803.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list