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