1 // RUN: %clang_cc1 -std=c++11 -fsanitize=signed-integer-overflow,integer-divide-by-zero,float-divide-by-zero,shift,unreachable,return,vla-bound,alignment,null,vptr,object-size,float-cast-overflow,bool,enum,array-bounds,function -fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,float-divide-by-zero,shift,vla-bound,alignment,null,vptr,object-size,float-cast-overflow,bool,enum,array-bounds,function -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
2 // RUN: %clang_cc1 -std=c++11 -fsanitize=vptr,address -fsanitize-recover=vptr,address -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK-ASAN
3 // RUN: %clang_cc1 -std=c++11 -fsanitize=vptr -fsanitize-recover=vptr -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=DOWNCAST-NULL
4
5 struct S {
6 double d;
7 int a, b;
8 virtual int f();
9 };
10
11 // Check that type descriptor global is not modified by ASan.
12 // CHECK-ASAN: [[TYPE_DESCR:@[0-9]+]] = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'S'\00" }
13
14 // Check that type mismatch handler is not modified by ASan.
15 // CHECK-ASAN: private unnamed_addr global { { [{{.*}} x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8*, i8 } { {{.*}}, { i16, i16, [4 x i8] }* [[TYPE_DESCR]], {{.*}} }
16
17 struct T : S {};
18
19 // CHECK-LABEL: @_Z17reference_binding
reference_binding(int * p,S * q)20 void reference_binding(int *p, S *q) {
21 // C++ core issue 453: If an lvalue to which a reference is directly bound
22 // designates neither an existing object or function of an appropriate type,
23 // nor a region of storage of suitable size and alignment to contain an object
24 // of the reference's type, the behavior is undefined.
25
26 // CHECK: icmp ne {{.*}}, null
27
28 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
29 // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4
30
31 // CHECK: %[[PTRINT:.*]] = ptrtoint
32 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3
33 // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
34 int &r = *p;
35
36 // A reference is not required to refer to an object within its lifetime.
37 // CHECK-NOT: __ubsan_handle_dynamic_type_cache_miss
38 S &r2 = *q;
39 }
40
41 // CHECK-LABEL: @_Z13member_access
42 // CHECK-ASAN-LABEL: @_Z13member_access
member_access(S * p)43 void member_access(S *p) {
44 // (1a) Check 'p' is appropriately sized and aligned for member access.
45
46 // CHECK: icmp ne {{.*}}, null
47
48 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
49 // CHECK-NEXT: icmp uge i64 %[[SIZE]], 24
50
51 // CHECK: %[[PTRINT:.*]] = ptrtoint
52 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 7
53 // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
54
55 // (1b) Check that 'p' actually points to an 'S'.
56
57 // CHECK: %[[VPTRADDR:.*]] = bitcast {{.*}} to i64*
58 // CHECK-NEXT: %[[VPTR:.*]] = load i64* %[[VPTRADDR]]
59 //
60 // hash_16_bytes:
61 //
62 // If this number changes, it indicates that either the mangled name of ::S
63 // has changed, or that LLVM's hashing function has changed. The latter case
64 // is OK if the hashing function is still stable.
65 //
66 // The two hash values are for 64- and 32-bit Clang binaries, respectively.
67 // FIXME: We should produce a 64-bit value either way.
68 //
69 // CHECK-NEXT: xor i64 {{-4030275160588942838|2562089159}}, %[[VPTR]]
70 // CHECK-NEXT: mul i64 {{.*}}, -7070675565921424023
71 // CHECK-NEXT: lshr i64 {{.*}}, 47
72 // CHECK-NEXT: xor i64
73 // CHECK-NEXT: xor i64 %[[VPTR]]
74 // CHECK-NEXT: mul i64 {{.*}}, -7070675565921424023
75 // CHECK-NEXT: lshr i64 {{.*}}, 47
76 // CHECK-NEXT: xor i64
77 // CHECK-NEXT: %[[HASH:.*]] = mul i64 {{.*}}, -7070675565921424023
78 //
79 // Check the hash against the table:
80 //
81 // CHECK-NEXT: %[[IDX:.*]] = and i64 %{{.*}}, 127
82 // CHECK-NEXT: getelementptr inbounds [128 x i64]* @__ubsan_vptr_type_cache, i32 0, i64 %[[IDX]]
83 // CHECK-NEXT: %[[CACHEVAL:.*]] = load i64*
84 // CHECK-NEXT: icmp eq i64 %[[CACHEVAL]], %[[HASH]]
85 // CHECK-NEXT: br i1
86
87 // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss({{.*}}, i64 %{{.*}}, i64 %[[HASH]])
88 // CHECK-NOT: unreachable
89 // CHECK: {{.*}}:
90
91 // (2) Check 'p->b' is appropriately sized and aligned for a load.
92
93 // FIXME: Suppress this in the trivial case of a member access, because we
94 // know we've just checked the member access expression itself.
95
96 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
97 // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4
98
99 // CHECK: %[[PTRINT:.*]] = ptrtoint
100 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3
101 // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
102 int k = p->b;
103
104 // (3a) Check 'p' is appropriately sized and aligned for member function call.
105
106 // CHECK: icmp ne {{.*}}, null
107
108 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64
109 // CHECK-NEXT: icmp uge i64 %[[SIZE]], 24
110
111 // CHECK: %[[PTRINT:.*]] = ptrtoint
112 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 7
113 // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
114
115 // (3b) Check that 'p' actually points to an 'S'
116
117 // CHECK: load i64*
118 // CHECK-NEXT: xor i64 {{-4030275160588942838|2562089159}},
119 // [...]
120 // CHECK: getelementptr inbounds [128 x i64]* @__ubsan_vptr_type_cache, i32 0, i64 %
121 // CHECK: br i1
122 // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss({{.*}}, i64 %{{.*}}, i64 %{{.*}})
123 // CHECK-NOT: unreachable
124 // CHECK: {{.*}}:
125
126 k = p->f();
127 }
128
129 // CHECK-LABEL: @_Z12lsh_overflow
lsh_overflow(int a,int b)130 int lsh_overflow(int a, int b) {
131 // CHECK: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31
132 // CHECK-NEXT: br i1 %[[INBOUNDS]]
133
134 // CHECK: %[[SHIFTED_OUT_WIDTH:.*]] = sub nuw nsw i32 31, %[[RHS]]
135 // CHECK-NEXT: %[[SHIFTED_OUT:.*]] = lshr i32 %[[LHS:.*]], %[[SHIFTED_OUT_WIDTH]]
136
137 // This is present for C++11 but not for C: C++ core issue 1457 allows a '1'
138 // to be shifted into the sign bit, but not out of it.
139 // CHECK-NEXT: %[[SHIFTED_OUT_NOT_SIGN:.*]] = lshr i32 %[[SHIFTED_OUT]], 1
140
141 // CHECK-NEXT: %[[NO_OVERFLOW:.*]] = icmp eq i32 %[[SHIFTED_OUT_NOT_SIGN]], 0
142
143 // CHECK: %[[VALID:.*]] = phi i1 [ %[[INBOUNDS]], {{.*}} ], [ %[[NO_OVERFLOW]], {{.*}} ]
144 // CHECK-NEXT: br i1 %[[VALID]]
145
146 // CHECK: call void @__ubsan_handle_shift_out_of_bounds
147 // CHECK-NOT: call void @__ubsan_handle_shift_out_of_bounds
148
149 // CHECK: %[[RET:.*]] = shl i32 %[[LHS]], %[[RHS]]
150 // CHECK-NEXT: ret i32 %[[RET]]
151 return a << b;
152 }
153
154 // CHECK-LABEL: @_Z9no_return
no_return()155 int no_return() {
156 // CHECK: call void @__ubsan_handle_missing_return(i8* bitcast ({{.*}}* @{{.*}} to i8*)) [[NR_NUW:#[0-9]+]]
157 // CHECK-NEXT: unreachable
158 }
159
160 // CHECK-LABEL: @_Z9sour_bool
sour_bool(bool * p)161 bool sour_bool(bool *p) {
162 // CHECK: %[[OK:.*]] = icmp ule i8 {{.*}}, 1
163 // CHECK: br i1 %[[OK]]
164 // CHECK: call void @__ubsan_handle_load_invalid_value(i8* bitcast ({{.*}}), i64 {{.*}})
165 return *p;
166 }
167
168 enum E1 { e1a = 0, e1b = 127 } e1;
169 enum E2 { e2a = -1, e2b = 64 } e2;
170 enum E3 { e3a = (1u << 31) - 1 } e3;
171
172 // CHECK-LABEL: @_Z14bad_enum_value
bad_enum_value()173 int bad_enum_value() {
174 // CHECK: %[[E1:.*]] = icmp ule i32 {{.*}}, 127
175 // CHECK: br i1 %[[E1]]
176 // CHECK: call void @__ubsan_handle_load_invalid_value(
177 int a = e1;
178
179 // CHECK: %[[E2HI:.*]] = icmp sle i32 {{.*}}, 127
180 // CHECK: %[[E2LO:.*]] = icmp sge i32 {{.*}}, -128
181 // CHECK: %[[E2:.*]] = and i1 %[[E2HI]], %[[E2LO]]
182 // CHECK: br i1 %[[E2]]
183 // CHECK: call void @__ubsan_handle_load_invalid_value(
184 int b = e2;
185
186 // CHECK: %[[E3:.*]] = icmp ule i32 {{.*}}, 2147483647
187 // CHECK: br i1 %[[E3]]
188 // CHECK: call void @__ubsan_handle_load_invalid_value(
189 int c = e3;
190 return a + b + c;
191 }
192
193 // CHECK-LABEL: @_Z20bad_downcast_pointer
194 // DOWNCAST-NULL-LABEL: @_Z20bad_downcast_pointer
bad_downcast_pointer(S * p)195 void bad_downcast_pointer(S *p) {
196 // CHECK: %[[NONNULL:.*]] = icmp ne {{.*}}, null
197 // CHECK: br i1 %[[NONNULL]],
198
199 // A null poiner access is guarded without -fsanitize=null.
200 // DOWNCAST-NULL: %[[NONNULL:.*]] = icmp ne {{.*}}, null
201 // DOWNCAST-NULL: br i1 %[[NONNULL]],
202
203 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64.p0i8(
204 // CHECK: %[[E1:.*]] = icmp uge i64 %[[SIZE]], 24
205 // CHECK: %[[MISALIGN:.*]] = and i64 %{{.*}}, 7
206 // CHECK: %[[E2:.*]] = icmp eq i64 %[[MISALIGN]], 0
207 // CHECK: %[[E12:.*]] = and i1 %[[E1]], %[[E2]]
208 // CHECK: br i1 %[[E12]],
209
210 // CHECK: call void @__ubsan_handle_type_mismatch
211 // CHECK: br label
212
213 // CHECK: br i1 %{{.*}},
214
215 // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss
216 // CHECK: br label
217 (void) static_cast<T*>(p);
218 }
219
220 // CHECK-LABEL: @_Z22bad_downcast_reference
bad_downcast_reference(S & p)221 void bad_downcast_reference(S &p) {
222 // CHECK: %[[E1:.*]] = icmp ne {{.*}}, null
223 // CHECK-NOT: br i1
224
225 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64.p0i8(
226 // CHECK: %[[E2:.*]] = icmp uge i64 %[[SIZE]], 24
227
228 // CHECK: %[[MISALIGN:.*]] = and i64 %{{.*}}, 7
229 // CHECK: %[[E3:.*]] = icmp eq i64 %[[MISALIGN]], 0
230
231 // CHECK: %[[E12:.*]] = and i1 %[[E1]], %[[E2]]
232 // CHECK: %[[E123:.*]] = and i1 %[[E12]], %[[E3]]
233 // CHECK: br i1 %[[E123]],
234
235 // CHECK: call void @__ubsan_handle_type_mismatch
236 // CHECK: br label
237
238 // CHECK: br i1 %{{.*}},
239
240 // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss
241 // CHECK: br label
242 (void) static_cast<T&>(p);
243 }
244
245 // CHECK-LABEL: @_Z11array_index
array_index(const int (& a)[4],int n)246 int array_index(const int (&a)[4], int n) {
247 // CHECK: %[[K1_OK:.*]] = icmp ult i64 %{{.*}}, 4
248 // CHECK: br i1 %[[K1_OK]]
249 // CHECK: call void @__ubsan_handle_out_of_bounds(
250 int k1 = a[n];
251
252 // CHECK: %[[R1_OK:.*]] = icmp ule i64 %{{.*}}, 4
253 // CHECK: br i1 %[[R1_OK]]
254 // CHECK: call void @__ubsan_handle_out_of_bounds(
255 const int *r1 = &a[n];
256
257 // CHECK: %[[K2_OK:.*]] = icmp ult i64 %{{.*}}, 8
258 // CHECK: br i1 %[[K2_OK]]
259 // CHECK: call void @__ubsan_handle_out_of_bounds(
260 int k2 = ((const int(&)[8])a)[n];
261
262 // CHECK: %[[K3_OK:.*]] = icmp ult i64 %{{.*}}, 4
263 // CHECK: br i1 %[[K3_OK]]
264 // CHECK: call void @__ubsan_handle_out_of_bounds(
265 int k3 = n[a];
266
267 return k1 + *r1 + k2;
268 }
269
270 // CHECK-LABEL: @_Z17multi_array_index
multi_array_index(int n,int m)271 int multi_array_index(int n, int m) {
272 int arr[4][6];
273
274 // CHECK: %[[IDX2_OK:.*]] = icmp ult i64 %{{.*}}, 6
275 // CHECK: br i1 %[[IDX2_OK]]
276 // CHECK: call void @__ubsan_handle_out_of_bounds(
277
278 // CHECK: %[[IDX1_OK:.*]] = icmp ult i64 %{{.*}}, 4
279 // CHECK: br i1 %[[IDX1_OK]]
280 // CHECK: call void @__ubsan_handle_out_of_bounds(
281 return arr[n][m];
282 }
283
284 // CHECK-LABEL: @_Z11array_arith
array_arith(const int (& a)[4],int n)285 int array_arith(const int (&a)[4], int n) {
286 // CHECK: %[[K1_OK:.*]] = icmp ule i64 %{{.*}}, 4
287 // CHECK: br i1 %[[K1_OK]]
288 // CHECK: call void @__ubsan_handle_out_of_bounds(
289 const int *k1 = a + n;
290
291 // CHECK: %[[K2_OK:.*]] = icmp ule i64 %{{.*}}, 8
292 // CHECK: br i1 %[[K2_OK]]
293 // CHECK: call void @__ubsan_handle_out_of_bounds(
294 const int *k2 = (const int(&)[8])a + n;
295
296 return *k1 + *k2;
297 }
298
299 struct ArrayMembers {
300 int a1[5];
301 int a2[1];
302 };
303 // CHECK-LABEL: @_Z18struct_array_index
struct_array_index(ArrayMembers * p,int n)304 int struct_array_index(ArrayMembers *p, int n) {
305 // CHECK: %[[IDX_OK:.*]] = icmp ult i64 %{{.*}}, 5
306 // CHECK: br i1 %[[IDX_OK]]
307 // CHECK: call void @__ubsan_handle_out_of_bounds(
308 return p->a1[n];
309 }
310
311 // CHECK-LABEL: @_Z16flex_array_index
flex_array_index(ArrayMembers * p,int n)312 int flex_array_index(ArrayMembers *p, int n) {
313 // CHECK-NOT: call void @__ubsan_handle_out_of_bounds(
314 return p->a2[n];
315 }
316
317 extern int incomplete[];
318 // CHECK-LABEL: @_Z22incomplete_array_index
incomplete_array_index(int n)319 int incomplete_array_index(int n) {
320 // CHECK-NOT: call void @__ubsan_handle_out_of_bounds(
321 return incomplete[n];
322 }
323
324 typedef __attribute__((ext_vector_type(4))) int V4I;
325 // CHECK-LABEL: @_Z12vector_index
vector_index(V4I v,int n)326 int vector_index(V4I v, int n) {
327 // CHECK: %[[IDX_OK:.*]] = icmp ult i64 %{{.*}}, 4
328 // CHECK: br i1 %[[IDX_OK]]
329 // CHECK: call void @__ubsan_handle_out_of_bounds(
330 return v[n];
331 }
332
333 // CHECK-LABEL: @_Z12string_index
string_index(int n)334 char string_index(int n) {
335 // CHECK: %[[IDX_OK:.*]] = icmp ult i64 %{{.*}}, 6
336 // CHECK: br i1 %[[IDX_OK]]
337 // CHECK: call void @__ubsan_handle_out_of_bounds(
338 return "Hello"[n];
339 }
340
341 class A // align=4
342 {
343 int a1, a2, a3;
344 };
345
346 class B // align=8
347 {
348 long b1, b2;
349 };
350
351 class C : public A, public B // align=16
352 {
353 alignas(16) int c1;
354 };
355
356 // Make sure we check the alignment of the pointer after subtracting any
357 // offset. The pointer before subtraction doesn't need to be aligned for
358 // the destination type.
359
360 // CHECK-LABEL: define void @_Z16downcast_pointerP1B(%class.B* %b)
downcast_pointer(B * b)361 void downcast_pointer(B *b) {
362 (void) static_cast<C*>(b);
363 // Alignment check from EmitTypeCheck(TCK_DowncastPointer, ...)
364 // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr i8* {{.*}}, i64 -16
365 // CHECK-NEXT: [[C:%[0-9]*]] = bitcast i8* [[SUB]] to %class.C*
366 // null check goes here
367 // CHECK: [[FROM_PHI:%[0-9]*]] = phi %class.C* [ [[C]], {{.*}} ], {{.*}}
368 // Objectsize check goes here
369 // CHECK: [[C_INT:%[0-9]*]] = ptrtoint %class.C* [[FROM_PHI]] to i64
370 // CHECK-NEXT: [[MASKED:%[0-9]*]] = and i64 [[C_INT]], 15
371 // CHECK-NEXT: [[TEST:%[0-9]*]] = icmp eq i64 [[MASKED]], 0
372 // AND the alignment test with the objectsize test.
373 // CHECK-NEXT: [[AND:%[0-9]*]] = and i1 {{.*}}, [[TEST]]
374 // CHECK-NEXT: br i1 [[AND]]
375 }
376
377 // CHECK-LABEL: define void @_Z18downcast_referenceR1B(%class.B* dereferenceable({{[0-9]+}}) %b)
downcast_reference(B & b)378 void downcast_reference(B &b) {
379 (void) static_cast<C&>(b);
380 // Alignment check from EmitTypeCheck(TCK_DowncastReference, ...)
381 // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr i8* {{.*}}, i64 -16
382 // CHECK-NEXT: [[C:%[0-9]*]] = bitcast i8* [[SUB]] to %class.C*
383 // Objectsize check goes here
384 // CHECK: [[C_INT:%[0-9]*]] = ptrtoint %class.C* [[C]] to i64
385 // CHECK-NEXT: [[MASKED:%[0-9]*]] = and i64 [[C_INT]], 15
386 // CHECK-NEXT: [[TEST:%[0-9]*]] = icmp eq i64 [[MASKED]], 0
387 // AND the alignment test with the objectsize test.
388 // CHECK: [[AND:%[0-9]*]] = and i1 {{.*}}, [[TEST]]
389 // CHECK-NEXT: br i1 [[AND]]
390 }
391
392 // CHECK-LABEL: @_Z22indirect_function_callPFviE({{.*}} prologue <{ i32, i8* }> <{ i32 1413876459, i8* bitcast ({ i8*, i8* }* @_ZTIFvPFviEE to i8*) }>
indirect_function_call(void (* p)(int))393 void indirect_function_call(void (*p)(int)) {
394 // CHECK: [[PTR:%[0-9]*]] = bitcast void (i32)* {{.*}} to <{ i32, i8* }>*
395
396 // Signature check
397 // CHECK-NEXT: [[SIGPTR:%[0-9]*]] = getelementptr <{ i32, i8* }>* [[PTR]], i32 0, i32 0
398 // CHECK-NEXT: [[SIG:%[0-9]*]] = load i32* [[SIGPTR]]
399 // CHECK-NEXT: [[SIGCMP:%[0-9]*]] = icmp eq i32 [[SIG]], 1413876459
400 // CHECK-NEXT: br i1 [[SIGCMP]]
401
402 // RTTI pointer check
403 // CHECK: [[RTTIPTR:%[0-9]*]] = getelementptr <{ i32, i8* }>* [[PTR]], i32 0, i32 1
404 // CHECK-NEXT: [[RTTI:%[0-9]*]] = load i8** [[RTTIPTR]]
405 // CHECK-NEXT: [[RTTICMP:%[0-9]*]] = icmp eq i8* [[RTTI]], bitcast ({ i8*, i8* }* @_ZTIFviE to i8*)
406 // CHECK-NEXT: br i1 [[RTTICMP]]
407 p(42);
408 }
409
410 namespace UpcastPointerTest {
411 struct S {};
412 struct T : S { double d; };
413 struct V : virtual S {};
414
415 // CHECK-LABEL: upcast_pointer
upcast_pointer(T * t)416 S* upcast_pointer(T* t) {
417 // Check for null pointer
418 // CHECK: %[[NONNULL:.*]] = icmp ne {{.*}}, null
419 // CHECK: br i1 %[[NONNULL]]
420
421 // Check alignment
422 // CHECK: %[[MISALIGN:.*]] = and i64 %{{.*}}, 7
423 // CHECK: icmp eq i64 %[[MISALIGN]], 0
424
425 // CHECK: call void @__ubsan_handle_type_mismatch
426 return t;
427 }
428
429 V getV();
430
431 // CHECK-LABEL: upcast_to_vbase
upcast_to_vbase()432 void upcast_to_vbase() {
433 // No need to check for null here, as we have a temporary here.
434
435 // CHECK-NOT: br i1
436
437 // CHECK: call i64 @llvm.objectsize
438 // CHECK: call void @__ubsan_handle_type_mismatch
439 // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss
440 const S& s = getV();
441 }
442 }
443
444 namespace CopyValueRepresentation {
445 // CHECK-LABEL: define {{.*}} @_ZN23CopyValueRepresentation2S3aSERKS0_
446 // CHECK-NOT: call {{.*}} @__ubsan_handle_load_invalid_value
447 // CHECK-LABEL: define {{.*}} @_ZN23CopyValueRepresentation2S4aSEOS0_
448 // CHECK-NOT: call {{.*}} @__ubsan_handle_load_invalid_value
449 // CHECK-LABEL: define {{.*}} @_ZN23CopyValueRepresentation2S5C2ERKS0_
450 // CHECK-NOT: call {{.*}} __ubsan_handle_load_invalid_value
451 // CHECK-LABEL: define {{.*}} @_ZN23CopyValueRepresentation2S2C2ERKS0_
452 // CHECK: __ubsan_handle_load_invalid_value
453 // CHECK-LABEL: define {{.*}} @_ZN23CopyValueRepresentation2S1C2ERKS0_
454 // CHECK-NOT: call {{.*}} __ubsan_handle_load_invalid_value
455
456 struct CustomCopy { CustomCopy(); CustomCopy(const CustomCopy&); };
457 struct S1 {
458 CustomCopy CC;
459 bool b;
460 };
461 void callee1(S1);
test1()462 void test1() {
463 S1 s11;
464 callee1(s11);
465 S1 s12;
466 s12 = s11;
467 }
468
469 static bool some_global_bool;
470 struct ExprCopy {
471 ExprCopy();
472 ExprCopy(const ExprCopy&, bool b = some_global_bool);
473 };
474 struct S2 {
475 ExprCopy EC;
476 bool b;
477 };
478 void callee2(S2);
test2(void)479 void test2(void) {
480 S2 s21;
481 callee2(s21);
482 S2 s22;
483 s22 = s21;
484 }
485
486 struct CustomAssign { CustomAssign &operator=(const CustomAssign&); };
487 struct S3 {
488 CustomAssign CA;
489 bool b;
490 };
test3()491 void test3() {
492 S3 x, y;
493 x = y;
494 }
495
496 struct CustomMove {
497 CustomMove();
498 CustomMove(const CustomMove&&);
499 CustomMove &operator=(const CustomMove&&);
500 };
501 struct S4 {
502 CustomMove CM;
503 bool b;
504 };
test4()505 void test4() {
506 S4 x, y;
507 x = static_cast<S4&&>(y);
508 }
509
510 struct EnumCustomCopy {
511 EnumCustomCopy();
512 EnumCustomCopy(const EnumCustomCopy&);
513 };
514 struct S5 {
515 EnumCustomCopy ECC;
516 bool b;
517 };
518 void callee5(S5);
test5()519 void test5() {
520 S5 s51;
521 callee5(s51);
522 S5 s52;
523 s52 = s51;
524 }
525 }
526
527 // CHECK: attributes [[NR_NUW]] = { noreturn nounwind }
528