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

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


LGTM.
> On 2015 Feb 26, at 16:41, David Blaikie <dblaikie at gmail.com> wrote:
> 
> rebase, improve error handling, test error handling
> 
> 
> http://reviews.llvm.org/D7649
> 
> Files:
>  lib/AsmParser/LLParser.cpp
>  lib/IR/AsmWriter.cpp
>  test/Assembler/invalid-load-mismatched-explicit-type.ll
>  test/Assembler/invalid-load-missing-explicit-type.ll
> 
> Index: lib/AsmParser/LLParser.cpp
> ===================================================================
> --- lib/AsmParser/LLParser.cpp
> +++ lib/AsmParser/LLParser.cpp
> @@ -5241,7 +5241,11 @@
>     Lex.Lex();
>   }
> 
> -  if (ParseTypeAndValue(Val, Loc, PFS) ||
> +  Type *Ty = nullptr;
> +  LocTy ExplicitTypeLoc = Lex.getLoc();
> +  if (ParseType(Ty) ||
> +      ParseToken(lltok::comma, "expected comma after load's type") ||
> +      ParseTypeAndValue(Val, Loc, PFS) ||
>       ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
>       ParseOptionalCommaAlign(Alignment, AteExtraComma))
>     return true;
> @@ -5254,6 +5258,10 @@
>   if (Ordering == Release || Ordering == AcquireRelease)
>     return Error(Loc, "atomic load cannot use Release ordering");
> 
> +  if (Ty != cast<PointerType>(Val->getType())->getElementType())
> +    return Error(ExplicitTypeLoc,
> +                 "explicit pointee type doesn't match operand's pointee type");
> +
>   Inst = new LoadInst(Val, "", isVolatile, Alignment, Ordering, Scope);
>   return AteExtraComma ? InstExtraComma : InstNormal;
> }
> 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 (auto *LI = dyn_cast<LoadInst>(&I)) {
> +      Out << ' ';
> +      TypePrinter.print(LI->getType(), 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-load-mismatched-explicit-type.ll
> ===================================================================
> --- /dev/null
> +++ test/Assembler/invalid-load-mismatched-explicit-type.ll
> @@ -0,0 +1,6 @@
> +; RUN: not llvm-as < %s 2>&1 | FileCheck %s
> +; CHECK: <stdin>:4:13: error: explicit pointee type doesn't match operand's pointee type
> +define void @test(i32* %t) {
> +  %x = load i16, i32* %t
> +  ret void
> +}
> Index: test/Assembler/invalid-load-missing-explicit-type.ll
> ===================================================================
> --- /dev/null
> +++ test/Assembler/invalid-load-missing-explicit-type.ll
> @@ -0,0 +1,6 @@
> +; RUN: not llvm-as < %s 2>&1 | FileCheck %s
> +; CHECK: <stdin>:4:18: error: expected comma after load's type
> +define void @test(i32* %t) {
> +  %x = load i32* %t
> +  ret void
> +}
> 
> EMAIL PREFERENCES
>  http://reviews.llvm.org/settings/panel/emailpreferences/
> <D7649.20807.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