1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsanitize=unsigned-integer-overflow -fsanitize-recover=unsigned-integer-overflow %s -emit-llvm -o - | FileCheck %s --check-prefix=RECOVER
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsanitize=unsigned-integer-overflow %s -emit-llvm -o - | FileCheck %s --check-prefix=ABORT
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsanitize=null,object-size,alignment -fsanitize-recover=object-size %s -emit-llvm -o - | FileCheck %s --check-prefix=PARTIAL
4 
5 // RECOVER: @test
6 // ABORT: @test
test()7 void test() {
8   extern volatile unsigned x, y, z;
9 
10   // RECOVER: uadd.with.overflow.i32
11   // RECOVER: ubsan_handle_add_overflow(
12   // RECOVER-NOT: unreachable
13   // ABORT: uadd.with.overflow.i32
14   // ABORT: ubsan_handle_add_overflow_abort(
15   // ABORT: unreachable
16   x = y + z;
17 }
18 
foo()19 void foo() {
20   union { int i; } u;
21   u.i=1;
22   // PARTIAL:      %[[CHECK0:.*]] = icmp ne {{.*}}* %[[PTR:.*]], null
23 
24   // PARTIAL:      %[[SIZE:.*]] = call i64 @llvm.objectsize.i64.p0i8(i8* {{.*}}, i1 false)
25   // PARTIAL-NEXT: %[[CHECK1:.*]] = icmp uge i64 %[[SIZE]], 4
26 
27   // PARTIAL:      %[[MISALIGN:.*]] = and i64 {{.*}}, 3
28   // PARTIAL-NEXT: %[[CHECK2:.*]] = icmp eq i64 %[[MISALIGN]], 0
29 
30   // PARTIAL:      %[[CHECK02:.*]] = and i1 %[[CHECK0]], %[[CHECK2]]
31   // PARTIAL-NEXT: %[[CHECK012:.*]] = and i1 %[[CHECK02]], %[[CHECK1]]
32 
33   // PARTIAL:      br i1 %[[CHECK012]], {{.*}} !prof ![[WEIGHT_MD:.*]], !nosanitize
34 
35   // PARTIAL:      br i1 %[[CHECK02]], {{.*}}
36   // PARTIAL:      call void @__ubsan_handle_type_mismatch_abort(
37   // PARTIAL-NEXT: unreachable
38   // PARTIAL:      call void @__ubsan_handle_type_mismatch(
39 }
40