diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-10-03 09:43:21 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-10-03 09:43:21 -0700 |
commit | ed6b15283ff5f9d13cb48f88ba6e189be11291e8 (patch) | |
tree | 3dcbfc6d6c202f8fa1b5f418e49b433eb07c8c80 /test | |
parent | 8ed96f4d0ca9b8114875997f1f0196fc89a41a04 (diff) |
PNaCl bitcode: Simplify how the writer elides casts
The PNaCl bitcode writer had some complex logic for deciding when to
omit casts in the output. This was left over from when the writer was
trying to leave in the casts in some but not all cases (as part of
incrementally removing casts).
This is no longer needed now that the writer just omits all inttoptrs,
all ptrtoints, and all pointer bitcasts.
This cleanup also fixes the writer so that it elides an inttoptr of a
ptrtoint. This sequence is allowed by the PNaCl ABI verifier, but
never occurred in practice because ReplacePtrsWithInts'
SimplifyCasts() function converts this sequence to an equivalent
bitcast. Before this change, the writer would give this error for an
inttoptr-of-ptrtoint:
LLVM ERROR: Illegal (PNaCl ABI) pointer cast : %1 = ptrtoint [4 x i8]* @bytes to i32
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3590
TEST=toolchain trybots
Review URL: https://codereview.chromium.org/25817002
Diffstat (limited to 'test')
-rw-r--r-- | test/NaCl/Bitcode/inttoptr-of-ptrtoint-elide.ll | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/NaCl/Bitcode/inttoptr-of-ptrtoint-elide.ll b/test/NaCl/Bitcode/inttoptr-of-ptrtoint-elide.ll new file mode 100644 index 0000000000..1d88ca5cd9 --- /dev/null +++ b/test/NaCl/Bitcode/inttoptr-of-ptrtoint-elide.ll @@ -0,0 +1,32 @@ +; Test that the writer elides an inttoptr of a ptrtoint. + +; RUN: llvm-as < %s | pnacl-freeze \ +; RUN: | pnacl-bcanalyzer -dump-records \ +; RUN: | FileCheck %s -check-prefix=PF2 + +; RUN: llvm-as < %s | pnacl-freeze | pnacl-thaw \ +; RUN: | llvm-dis - | FileCheck %s -check-prefix=TD2 + + +@bytes = internal global [4 x i8] c"abcd" + +define void @inttoptr_of_ptrtoint() { + ; These two instructions are usually replaced with an equivalent + ; bitcast, but either sequence is allowed by the PNaCl ABI verifier. + %1 = ptrtoint [4 x i8]* @bytes to i32 + %2 = inttoptr i32 %1 to i8* + load i8* %2 + ret void +} + +; TD2: define void @inttoptr_of_ptrtoint() { +; TD2-NEXT: %1 = bitcast [4 x i8]* @bytes to i8* +; TD2-NEXT: %2 = load i8* %1 +; TD2-NEXT: ret void +; TD2-NEXT: } + +; PF2: <FUNCTION_BLOCK> +; PF2-NEXT: <DECLAREBLOCKS op0=1/> +; PF2-NEXT: <INST_LOAD {{.*}}/> +; PF2-NEXT: <INST_RET/> +; PF2: </FUNCTION_BLOCK> |