llvm-project

Форк
0
196 строк · 6.0 Кб
1
; RUN: opt -aa-pipeline=basic-aa -passes=lint -disable-output < %s 2>&1 | FileCheck %s
2
target datalayout = "e-p:64:64:64"
3

4
declare fastcc void @bar()
5
declare void @llvm.stackrestore(ptr)
6
declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
7
declare void @llvm.memcpy.inline.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
8
declare void @llvm.memset.p0.i8.i64(ptr nocapture, i8, i64, i1) nounwind
9
declare void @llvm.memset.inline.p0.i8.i64(ptr nocapture, i8, i64, i1) nounwind
10
declare void @has_sret(ptr sret(i8) %p)
11
declare void @has_noaliases(ptr noalias %p, ptr %q)
12
declare void @one_arg(i32)
13

14
@CG = constant i32 7
15
@CG2 = constant i32 7
16
@E = external global i8
17

18
define i32 @foo() noreturn {
19
  %buf = alloca i8
20
  %buf2 = alloca {i8, i8}, align 2
21
; CHECK: Caller and callee calling convention differ
22
  call void @bar()
23
; CHECK: Null pointer dereference
24
  store i32 0, ptr null
25
; CHECK: Null pointer dereference
26
  %t = load i32, ptr null
27
; CHECK: Undef pointer dereference
28
  store i32 0, ptr undef
29
; CHECK: Undef pointer dereference
30
  %u = load i32, ptr undef
31
; CHECK: All-ones pointer dereference
32
  store i32 0, ptr inttoptr (i64 -1 to ptr)
33
; CHECK: Address one pointer dereference
34
  store i32 0, ptr inttoptr (i64 1 to ptr)
35
; CHECK: Memory reference address is misaligned
36
  store i8 0, ptr %buf, align 2
37
; CHECK: Memory reference address is misaligned
38
  %gep = getelementptr {i8, i8}, ptr %buf2, i32 0, i32 1
39
  store i8 0, ptr %gep, align 2
40
; CHECK: Division by zero
41
  %sd = sdiv i32 2, 0
42
; CHECK: Division by zero
43
  %ud = udiv i32 2, 0
44
; CHECK: Division by zero
45
  %sr = srem i32 2, 0
46
; CHECK: Division by zero
47
  %ur = urem i32 2, 0
48
; CHECK: extractelement index out of range
49
  %ee = extractelement <4 x i32> zeroinitializer, i32 4
50
; CHECK: insertelement index out of range
51
  %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
52
; CHECK: Shift count out of range
53
  %r = lshr i32 0, 32
54
; CHECK: Shift count out of range
55
  %q = ashr i32 0, 32
56
; CHECK: Shift count out of range
57
  %l = shl i32 0, 32
58
; CHECK: xor(undef, undef)
59
  %xx = xor i32 undef, undef
60
; CHECK: sub(undef, undef)
61
  %xs = sub i32 undef, undef
62

63
; CHECK: Write to read-only memory
64
  store i32 8, ptr @CG
65
; CHECK: Write to text section
66
  store i32 8, ptr @foo
67
; CHECK: Load from block address
68
  %lb = load i32, ptr blockaddress(@foo, %next)
69
; CHECK: Call to block address
70
  call void() blockaddress(@foo, %next)()
71
; CHECK: Undefined behavior: Null pointer dereference
72
  call void @llvm.stackrestore(ptr null)
73
; CHECK: Undefined behavior: Null pointer dereference
74
  call void @has_sret(ptr sret(i8) null)
75
; CHECK: Unusual: noalias argument aliases another argument
76
  call void @has_noaliases(ptr @CG, ptr @CG)
77
; CHECK: Call argument count mismatches callee argument count
78
  call void (i32, i32) @one_arg(i32 0, i32 0)
79
; CHECK: Call argument count mismatches callee argument count
80
  call void () @one_arg()
81
; CHECK: Call argument type mismatches callee parameter type
82
  call void (float) @one_arg(float 0.0)
83

84
; CHECK: Write to read-only memory
85
call void @llvm.memcpy.p0.p0.i64(ptr @CG, ptr @CG2, i64 1, i1 0)
86
; CHECK: Write to read-only memory
87
call void @llvm.memcpy.inline.p0.p0.i64(ptr @CG, ptr @CG2, i64 1, i1 0)
88
; CHECK: Unusual: noalias argument aliases another argument
89
call void @llvm.memcpy.p0.p0.i64(ptr @CG, ptr @CG, i64 1, i1 0)
90

91
; CHECK: Write to read-only memory
92
call void @llvm.memset.p0.i8.i64(ptr @CG, i8 1, i64 1, i1 0)
93
; CHECK: Write to read-only memory
94
call void @llvm.memset.inline.p0.i8.i64(ptr @CG, i8 1, i64 1, i1 0)
95

96
; CHECK: Undefined behavior: Buffer overflow
97
  store i16 0, ptr %buf
98
; CHECK: Undefined behavior: Buffer overflow
99
  %inner = getelementptr {i8, i8}, ptr %buf2, i32 0, i32 1
100
  store i16 0, ptr %inner
101
; CHECK: Undefined behavior: Buffer overflow
102
  %before = getelementptr i8, ptr %buf, i32 -1
103
  store i16 0, ptr %before
104

105
  br label %next
106

107
next:
108
; CHECK: Static alloca outside of entry block
109
  %a = alloca i32
110
; CHECK: Return statement in function with noreturn attribute
111
  ret i32 0
112

113
foo:
114
; CHECK-NOT: Undefined behavior: Buffer overflow
115
; CHECK-NOT: Memory reference address is misaligned
116
  store i64 0, ptr @E
117
  %z = add i32 0, 0
118
; CHECK: unreachable immediately preceded by instruction without side effects
119
  unreachable
120
}
121

122
; CHECK: Unnamed function with non-local linkage
123
define void @0() nounwind {
124
  ret void
125
}
126

127
; CHECK: Undefined behavior: Branch to non-blockaddress
128
define void @use_indbr() {
129
  indirectbr ptr @foo, [label %block]
130
block:
131
  unreachable
132
}
133

134
; CHECK: Undefined behavior: Call with "tail" keyword references alloca
135
declare void @tailcallee(ptr)
136
define void @use_tail(ptr %valist) {
137
  %t = alloca i8
138
  tail call void @tailcallee(ptr %t)
139
  ret void
140
}
141

142
; CHECK: Unusual: Returning alloca value
143
define ptr @return_local(i32 %n, i32 %m) {
144
  %t = alloca i8, i32 %n
145
  %s = getelementptr i8, ptr %t, i32 %m
146
  ret ptr %s
147
}
148

149
; CHECK: Unusual: Returning alloca value
150
define ptr @return_obscured_local() {
151
entry:
152
  %retval = alloca ptr
153
  %x = alloca i32
154
  store ptr %x, ptr %retval
155
  br label %next
156
next:
157
  %t0 = load ptr, ptr %retval
158
  %t1 = insertvalue { i32, i32, ptr } zeroinitializer, ptr %t0, 2
159
  %t2 = extractvalue { i32, i32, ptr } %t1, 2
160
  br label %exit
161
exit:
162
  %t3 = phi ptr [ %t2, %next ]
163
  %t5 = ptrtoint ptr %t3 to i64
164
  %t6 = add i64 %t5, 0
165
  %t7 = inttoptr i64 %t6 to ptr
166
  ret ptr %t7
167
}
168

169
; CHECK: Undefined behavior: Undef pointer dereference
170
define ptr @self_reference() {
171
entry:
172
  unreachable
173
exit:
174
  %t3 = phi ptr [ %t4, %exit ]
175
  %t4 = bitcast ptr %t3 to ptr
176
  %x = load volatile i32, ptr %t3
177
  br label %exit
178
}
179

180
; CHECK: Call return type mismatches callee return type
181
%struct = type { double, double }
182
declare i32 @nonstruct_callee() nounwind
183
define void @struct_caller() nounwind {
184
entry:
185
  call %struct @foo()
186

187
  ; CHECK: Undefined behavior: indirectbr with no destinations
188
  indirectbr ptr null, []
189
}
190

191
define i32 @memcpy_inline_same_address() noreturn {
192
  %buf = alloca i64, align 1
193
  ; CHECK: Unusual: noalias argument aliases another argument
194
  call void @llvm.memcpy.inline.p0.p0.i64(ptr %buf, ptr %buf, i64 1, i1 false)
195
  unreachable
196
}
197

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.