xref: /llvm-project/llvm/test/Verifier/gcroot.ll (revision b05c71814c3b9f91a2e00af891d67a83790a109c)
1; RUN: not llvm-as -o /dev/null %s 2>&1 | FileCheck %s
2; PR1633
3
4declare void @llvm.gcroot(ptr, ptr)
5
6define void @caller_must_use_gc() {
7  ; CHECK: Enclosing function does not use GC.
8  ; CHECK-NEXT: call void @llvm.gcroot(ptr %alloca, ptr null)
9  %alloca = alloca ptr
10  call void @llvm.gcroot(ptr %alloca, ptr null)
11  ret void
12}
13
14define void @must_be_alloca() gc "test" {
15; CHECK: llvm.gcroot parameter #1 must be an alloca.
16; CHECK-NEXT: call void @llvm.gcroot(ptr null, ptr null)
17  call void @llvm.gcroot(ptr null, ptr null)
18  ret void
19}
20
21define void @non_ptr_alloca_null() gc "test" {
22  ; CHECK: llvm.gcroot parameter #1 must either be a pointer alloca, or argument #2 must be a non-null constant.
23  ; CHECK-NEXT: call void @llvm.gcroot(ptr %alloca, ptr null)
24  %alloca = alloca i32
25  call void @llvm.gcroot(ptr %alloca, ptr null)
26  ret void
27}
28
29define void @non_constant_arg1(ptr %arg) gc "test" {
30  ; CHECK: llvm.gcroot parameter #2 must be a constant.
31  ; CHECK-NEXT: call void @llvm.gcroot(ptr %alloca, ptr %arg)
32  %alloca = alloca ptr
33  call void @llvm.gcroot(ptr %alloca, ptr %arg)
34  ret void
35}
36
37define void @non_ptr_alloca_non_null() gc "test" {
38; CHECK-NOT: llvm.gcroot parameter
39  %alloca = alloca i32
40  call void @llvm.gcroot(ptr %alloca, ptr inttoptr (i64 123 to ptr))
41  ret void
42}
43
44define void @casted_alloca() gc "test" {
45; CHECK-NOT: llvm.gcroot parameter
46  %alloca = alloca ptr
47  call void @llvm.gcroot(ptr %alloca, ptr null)
48  ret void
49}
50