diff options
author | Anna Thomas <anna@azul.com> | 2017-07-05 01:16:29 +0000 |
---|---|---|
committer | Anna Thomas <anna@azul.com> | 2017-07-05 01:16:29 +0000 |
commit | 740f529dba1ff5acc1265bb03bd85014566692e6 (patch) | |
tree | a38ad00a709a68aa07d36e5350d88bc0ed4c61f2 /llvm/test/SafepointIRVerifier | |
parent | a24aa1990084c15f0ad27dbcff7ab1c96369f0f9 (diff) | |
download | llvm-740f529dba1ff5acc1265bb03bd85014566692e6.zip llvm-740f529dba1ff5acc1265bb03bd85014566692e6.tar.gz llvm-740f529dba1ff5acc1265bb03bd85014566692e6.tar.bz2 |
[SafepointIRVerifier] Add verifier pass for finding GC relocation bugs
Original Patch and summary by Philip Reames.
RewriteStatepointsForGC tries to rewrite a function in a manner where
the optimizer can't end up using a pointer value after it might have
been relocated by a safepoint. This pass checks the invariant that
RSForGC is supposed to establish and that (if we constructed semantics
correctly) later passes must preserve.
This has been a really useful diagnostic tool when initially developing
the rewriting scheme and has found numerous bugs.
Differential Revision: https://reviews.llvm.org/D15940
Reviewed by: swaroop.sridhar, mjacob
Subscribers: llvm-commits
llvm-svn: 307112
Diffstat (limited to 'llvm/test/SafepointIRVerifier')
4 files changed, 242 insertions, 0 deletions
diff --git a/llvm/test/SafepointIRVerifier/basic-use-after-reloc.ll b/llvm/test/SafepointIRVerifier/basic-use-after-reloc.ll new file mode 100644 index 0000000..4b0746c --- /dev/null +++ b/llvm/test/SafepointIRVerifier/basic-use-after-reloc.ll @@ -0,0 +1,23 @@ +; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s + +; This test checks that if a value is used immediately after a +; safepoint without using the relocated value that the verifier +; catches this. + +%jObject = type { [8 x i8] } + +; Function Attrs: nounwind +define %jObject addrspace(1)* @test(%jObject addrspace(1)* %arg) gc "statepoint-example" { +bci_0: + %safepoint_token3 = tail call token (i64, i32, double (double)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_f64f64f(i64 0, i32 0, double (double)* undef, i32 1, i32 0, double undef, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, %jObject addrspace(1)* %arg) + %arg2.relocated4 = call coldcc %jObject addrspace(1)* @llvm.experimental.gc.relocate.p1jObject(token %safepoint_token3, i32 13, i32 13) + ret %jObject addrspace(1)* %arg +; CHECK: Illegal use of unrelocated value found! +; CHECK-NEXT: Def: %jObject addrspace(1)* %arg +; CHECK-NEXT: Use: ret %jObject addrspace(1)* %arg +} + +; Function Attrs: nounwind +declare %jObject addrspace(1)* @llvm.experimental.gc.relocate.p1jObject(token, i32, i32) #3 + +declare token @llvm.experimental.gc.statepoint.p0f_f64f64f(i64, i32, double (double)*, i32, i32, ...) diff --git a/llvm/test/SafepointIRVerifier/constant-bases.ll b/llvm/test/SafepointIRVerifier/constant-bases.ll new file mode 100644 index 0000000..52a2a46 --- /dev/null +++ b/llvm/test/SafepointIRVerifier/constant-bases.ll @@ -0,0 +1,70 @@ +; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s + +define i8 addrspace(1)* @test1(i64 %arg) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test1 +entry: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + ret i8 addrspace(1)* null +} + +define i8 addrspace(1)* @test2(i64 %arg) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test2 +entry: + %load_addr = getelementptr i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*), i64 %arg + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + ret i8 addrspace(1)* %load_addr +} + +define i8 addrspace(1)* @test3(i64 %arg) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test3 +entry: + %load_addr = getelementptr i32, i32 addrspace(1)* inttoptr (i64 15 to i32 addrspace(1)*), i64 %arg + %load_addr.cast = bitcast i32 addrspace(1)* %load_addr to i8 addrspace(1)* + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + ret i8 addrspace(1)* %load_addr.cast +} + +define i8 addrspace(1)* @test4(i64 %arg, i1 %cond) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test4 +entry: + %load_addr.1 = getelementptr i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*), i64 %arg + br i1 %cond, label %split, label %join + +split: + %load_addr.2 = getelementptr i8, i8 addrspace(1)* inttoptr (i64 30 to i8 addrspace(1)*), i64 %arg + br label %join + +join: + %load_addr = phi i8 addrspace(1)* [%load_addr.1, %entry], [%load_addr.2, %split] + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + ret i8 addrspace(1)* %load_addr +} + +define i8 addrspace(1)* @test5(i64 %arg, i1 %cond) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test5 +entry: + %load_addr.1 = getelementptr i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*), i64 %arg + %load_addr.2 = getelementptr i8, i8 addrspace(1)* inttoptr (i64 30 to i8 addrspace(1)*), i64 %arg + %load_addr = select i1 %cond, i8 addrspace(1)* %load_addr.1, i8 addrspace(1)* %load_addr.2 + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + ret i8 addrspace(1)* %load_addr +} + +define i8 addrspace(1)* @test6(i64 %arg, i1 %cond, i8 addrspace(1)* %base) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test6 +; CHECK: Illegal use of unrelocated value found! +entry: + %load_addr.1 = getelementptr i8, i8 addrspace(1)* %base, i64 %arg + br i1 %cond, label %split, label %join + +split: + %load_addr.2 = getelementptr i8, i8 addrspace(1)* inttoptr (i64 30 to i8 addrspace(1)*), i64 %arg + br label %join + +join: + %load_addr = phi i8 addrspace(1)* [%load_addr.1, %entry], [%load_addr.2, %split] + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + ret i8 addrspace(1)* %load_addr +} + +declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) diff --git a/llvm/test/SafepointIRVerifier/unrecorded-live-at-sp.ll b/llvm/test/SafepointIRVerifier/unrecorded-live-at-sp.ll new file mode 100644 index 0000000..e3f21c3 --- /dev/null +++ b/llvm/test/SafepointIRVerifier/unrecorded-live-at-sp.ll @@ -0,0 +1,71 @@ +; RUN: opt %s -safepoint-ir-verifier-print-only -verify-safepoint-ir -S 2>&1 | FileCheck %s + +; CHECK: Illegal use of unrelocated value found! +; CHECK-NEXT: Def: %base_phi3 = phi %jObject addrspace(1)* [ %obj609.relocated, %not_zero146 ], [ %base_phi2, %bci_37-aload ], !is_base_value !0 +; CHECK-NEXT: Use: %base_phi2 = phi %jObject addrspace(1)* [ %base_phi3, %not_zero179 ], [ %cast5, %bci_0 ], !is_base_value !0 + +%jObject = type { [8 x i8] } + +declare %jObject addrspace(1)* @generate_obj1() #1 + +declare %jObject addrspace(1)* addrspace(1)* @generate_obj2() #1 + +declare %jObject addrspace(1)* @generate_obj3() #1 + +; Function Attrs: nounwind +define void @test(%jObject addrspace(1)*, %jObject addrspace(1)*, i32) #3 gc "statepoint-example" { +bci_0: + %result608 = call %jObject addrspace(1)* @generate_obj3() + %obj609 = bitcast %jObject addrspace(1)* %result608 to %jObject addrspace(1)* + %cast = bitcast %jObject addrspace(1)* %result608 to %jObject addrspace(1)* + %cast5 = bitcast %jObject addrspace(1)* %result608 to %jObject addrspace(1)* + br label %bci_37-aload + +bci_37-aload: ; preds = %not_zero179, %bci_0 + %base_phi = phi %jObject addrspace(1)* [ %base_phi1.relocated, %not_zero179 ], [ %cast, %bci_0 ], !is_base_value !0 + %base_phi2 = phi %jObject addrspace(1)* [ %base_phi3, %not_zero179 ], [ %cast5, %bci_0 ], !is_base_value !0 + %relocated8 = phi %jObject addrspace(1)* [ %relocated7.relocated, %not_zero179 ], [ %obj609, %bci_0 ] + %tmp3 = getelementptr inbounds %jObject, %jObject addrspace(1)* %relocated8, i64 0, i32 0, i64 32 + %addr98 = bitcast i8 addrspace(1)* %tmp3 to %jObject addrspace(1)* addrspace(1)* + %cast6 = bitcast %jObject addrspace(1)* %base_phi2 to %jObject addrspace(1)* addrspace(1)* + br i1 undef, label %not_zero179, label %not_zero146 + +not_zero146: ; preds = %bci_37-aload + %addr98.relocated = call %jObject addrspace(1)* addrspace(1)* @generate_obj2() #1 + %obj609.relocated = call %jObject addrspace(1)* @generate_obj1() #1 + br label %not_zero179 + +not_zero179: ; preds = %not_zero146, %bci_37-aload + %base_phi1 = phi %jObject addrspace(1)* [ %obj609.relocated, %not_zero146 ], [ %base_phi, %bci_37-aload ], !is_base_value !0 + %base_phi3 = phi %jObject addrspace(1)* [ %obj609.relocated, %not_zero146 ], [ %base_phi2, %bci_37-aload ], !is_base_value !0 + %relocated7 = phi %jObject addrspace(1)* [ %obj609.relocated, %not_zero146 ], [ %relocated8, %bci_37-aload ] + %base_phi4 = phi %jObject addrspace(1)* addrspace(1)* [ %addr98.relocated, %not_zero146 ], [ %cast6, %bci_37-aload ], !is_base_value !0 + %relocated4 = phi %jObject addrspace(1)* addrspace(1)* [ %addr98.relocated, %not_zero146 ], [ %addr98, %bci_37-aload ] + %safepoint_token = tail call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 0, i32 0, i32 ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 0, i32 0, %jObject addrspace(1)* %base_phi1, %jObject addrspace(1)* addrspace(1)* %base_phi4, %jObject addrspace(1)* addrspace(1)* %relocated4, %jObject addrspace(1)* %relocated7) + %tmp4 = call i32 @llvm.experimental.gc.result.i32(token %safepoint_token) + %base_phi1.relocated = call coldcc %jObject addrspace(1)* @llvm.experimental.gc.relocate.p1jObject(token %safepoint_token, i32 12, i32 12) + %base_phi4.relocated = call coldcc %jObject addrspace(1)* addrspace(1)* @llvm.experimental.gc.relocate.p1p1jObject(token %safepoint_token, i32 13, i32 13) + %relocated4.relocated = call coldcc %jObject addrspace(1)* addrspace(1)* @llvm.experimental.gc.relocate.p1p1jObject(token %safepoint_token, i32 13, i32 14) + %relocated7.relocated = call coldcc %jObject addrspace(1)* @llvm.experimental.gc.relocate.p1jObject(token %safepoint_token, i32 12, i32 15) + %addr636 = bitcast %jObject addrspace(1)* addrspace(1)* %relocated4.relocated to %jObject addrspace(1)* addrspace(1)* + br label %bci_37-aload +} + +declare token @llvm.experimental.gc.statepoint.p0f_i32f(i64, i32, i32 ()*, i32, i32, ...) + +; Function Attrs: nounwind +declare i32 @llvm.experimental.gc.result.i32(token) #4 + +; Function Attrs: nounwind +declare %jObject addrspace(1)* @llvm.experimental.gc.relocate.p1jObject(token, i32, i32) #4 + +; Function Attrs: nounwind +declare %jObject addrspace(1)* addrspace(1)* @llvm.experimental.gc.relocate.p1p1jObject(token, i32, i32) #4 + +attributes #0 = { noinline nounwind "gc-leaf-function"="true" } +attributes #1 = { "gc-leaf-function"="true" } +attributes #2 = { nounwind readonly "gc-leaf-function"="true" } +attributes #3 = { nounwind } +attributes #4 = { nounwind } + +!0 = !{i32 1} diff --git a/llvm/test/SafepointIRVerifier/uses-in-phi-nodes.ll b/llvm/test/SafepointIRVerifier/uses-in-phi-nodes.ll new file mode 100644 index 0000000..d06eb6e0 --- /dev/null +++ b/llvm/test/SafepointIRVerifier/uses-in-phi-nodes.ll @@ -0,0 +1,78 @@ +; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s + +define i8 addrspace(1)* @test.not.ok.0(i8 addrspace(1)* %arg) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test.not.ok.0 + bci_0: + br i1 undef, label %left, label %right + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: +; CHECK: Illegal use of unrelocated value found! +; CHECK-NEXT: Def: i8 addrspace(1)* %arg +; CHECK-NEXT: Use: %val = phi i8 addrspace(1)* [ %arg, %left ], [ %arg, %right ] + %val = phi i8 addrspace(1)* [ %arg, %left ], [ %arg, %right] + ret i8 addrspace(1)* %val +} + +define i8 addrspace(1)* @test.not.ok.1(i8 addrspace(1)* %arg) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test.not.ok.1 + bci_0: + br i1 undef, label %left, label %right + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: +; CHECK: Illegal use of unrelocated value found! +; CHECK-NEXT: Def: i8 addrspace(1)* %arg +; CHECK-NEXT: Use: %val = phi i8 addrspace(1)* [ %arg, %left ], [ null, %right ] + %val = phi i8 addrspace(1)* [ %arg, %left ], [ null, %right] + ret i8 addrspace(1)* %val +} + +define i8 addrspace(1)* @test.ok.0(i8 addrspace(1)* %arg) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test.ok.0 + bci_0: + br i1 undef, label %left, label %right + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: + %val = phi i8 addrspace(1)* [ null, %left ], [ null, %right] + ret i8 addrspace(1)* %val +} + +define i8 addrspace(1)* @test.ok.1(i8 addrspace(1)* %arg) gc "statepoint-example" { +; CHECK: No illegal uses found by SafepointIRVerifier in: test.ok.1 + bci_0: + br i1 undef, label %left, label %right + + left: + call void @not_statepoint() + br label %merge + + right: + br label %merge + + merge: + %val = phi i8 addrspace(1)* [ %arg, %left ], [ %arg, %right] + ret i8 addrspace(1)* %val +} + +declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) +declare void @not_statepoint() |