1 ; RUN: not opt -S %s -verify 2>&1 | FileCheck %s
3 declare token @llvm.call.preallocated.setup(i32)
4 declare i8* @llvm.call.preallocated.arg(token, i32)
5 declare void @llvm.call.preallocated.teardown(token)
7 ; Fake LLVM intrinsic to return a token
8 declare token @llvm.what()
11 declare void @foo1(i32* preallocated(i32))
12 declare void @foo2(i32* preallocated(i32), i32*, i32* preallocated(i32))
13 declare i32 @blackbox()
15 ; CHECK: llvm.call.preallocated.arg must be called with a "preallocated" call site attribute
16 define void @preallocated_arg_missing_preallocated_attribute() {
17 %cs = call token @llvm.call.preallocated.setup(i32 1)
18 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0)
19 %y = bitcast i8* %x to i32*
20 call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)]
24 ; CHECK: preallocated as a call site attribute can only be on llvm.call.preallocated.arg
25 define void @preallocated_call_site_attribute_not_on_arg() {
26 call void @foo0() preallocated(i32)
30 ; CHECK: "preallocated" argument must be a token from llvm.call.preallocated.setup
31 define void @preallocated_bundle_token() {
32 %i = call i32 @blackbox()
33 call void @foo0() ["preallocated"(i32 %i)]
37 ; CHECK: "preallocated" argument must be a token from llvm.call.preallocated.setup
38 define void @preallocated_bundle_token_from_setup() {
39 %cs = call token @llvm.what()
40 call void @foo0() ["preallocated"(token %cs)]
44 ; CHECK: Expected exactly one preallocated bundle operand
45 define void @preallocated_bundle_one_token() {
46 %cs0 = call token @llvm.call.preallocated.setup(i32 0)
47 %cs1 = call token @llvm.call.preallocated.setup(i32 0)
48 call void @foo0() ["preallocated"(token %cs0, token %cs1)]
52 ; CHECK: Multiple preallocated operand bundles
53 define void @preallocated_multiple_bundles() {
54 %cs0 = call token @llvm.call.preallocated.setup(i32 0)
55 %cs1 = call token @llvm.call.preallocated.setup(i32 0)
56 call void @foo0() ["preallocated"(token %cs0), "preallocated"(token %cs1)]
60 ; CHECK: Can have at most one call
61 define void @preallocated_one_call() {
62 %cs = call token @llvm.call.preallocated.setup(i32 1)
63 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
64 %y = bitcast i8* %x to i32*
65 call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)]
66 call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)]
70 ; CHECK: must be a constant
71 define void @preallocated_setup_constant() {
72 %ac = call i32 @blackbox()
73 %cs = call token @llvm.call.preallocated.setup(i32 %ac)
77 ; CHECK: must be between 0 and corresponding
78 define void @preallocated_setup_arg_index_in_bounds() {
79 %cs = call token @llvm.call.preallocated.setup(i32 2)
80 %a0 = call i8* @llvm.call.preallocated.arg(token %cs, i32 2) preallocated(i32)
84 ; CHECK: Attribute 'preallocated' type does not match parameter
85 define void @preallocated_attribute_type_mismatch() {
86 %cs = call token @llvm.call.preallocated.setup(i32 1)
87 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
88 %y = bitcast i8* %x to i32*
89 call void @foo1(i32* preallocated(i8) %y) ["preallocated"(token %cs)]
93 ; CHECK: preallocated operand either requires a preallocated bundle or the call to be musttail
94 define void @preallocated_require_bundle() {
95 %cs = call token @llvm.call.preallocated.setup(i32 1)
96 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
97 %y = bitcast i8* %x to i32*
98 call void @foo1(i32* preallocated(i32) %y)
102 ; CHECK: arg size must be equal to number of preallocated arguments
103 define void @preallocated_num_args() {
104 %cs = call token @llvm.call.preallocated.setup(i32 3)
105 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
106 %x1 = bitcast i8* %x to i32*
107 %y = call i8* @llvm.call.preallocated.arg(token %cs, i32 1) preallocated(i32)
108 %y1 = bitcast i8* %y to i32*
109 %a = inttoptr i32 0 to i32*
110 call void @foo2(i32* preallocated(i32) %x1, i32* %a, i32* preallocated(i32) %y1) ["preallocated"(token %cs)]
114 ; CHECK: token argument must be a llvm.call.preallocated.setup
115 define void @preallocated_arg_token() {
116 %t = call token @llvm.what()
117 %x = call i8* @llvm.call.preallocated.arg(token %t, i32 1) preallocated(i32)
121 ; CHECK: cannot use preallocated intrinsics on a call without preallocated arguments
122 define void @preallocated_no_preallocated_args() {
123 %cs = call token @llvm.call.preallocated.setup(i32 0)
124 call void @foo0() ["preallocated"(token %cs)]
128 ; CHECK: preallocated operand either requires a preallocated bundle or the call to be musttail
129 define void @musttail_and_bundle(i32* preallocated(i32) %a) {
130 %cs = call token @llvm.call.preallocated.setup(i32 0)
131 musttail call void @musttail_and_bundle(i32* preallocated(i32) %a) ["preallocated"(token %cs)]
135 ; CHECK: cannot guarantee tail call due to mismatched ABI impacting function attributes
136 define void @musttail_attr_no_match(i32* preallocated(i32) %a) {
137 musttail call void @musttail_and_bundle(i32* %a)
141 ; CHECK: token argument must be a llvm.call.preallocated.setup
142 define void @teardown_token_not_from_setup() {
143 %cs = call token @llvm.what()
144 call void @llvm.call.preallocated.teardown(token %cs)
148 ; CHECK: Attribute 'preallocated(i32)' applied to incompatible type!
149 ; CHECK-NEXT: void (i32)* @not_pointer
150 declare void @not_pointer(i32 preallocated(i32))