11// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2- // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O1 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm -ubsan-guard-checks | FileCheck %s
3- // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O1 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm -ubsan-guard-checks -fsanitize-trap=signed-integer-overflow,integer-divide-by-zero,null | FileCheck %s --check-prefixes=TR
4- // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O1 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm -ubsan-guard-checks -fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,null | FileCheck %s --check-prefixes=REC
2+ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O1 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null,local-bounds -mllvm -ubsan-guard-checks | FileCheck %s
3+ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O1 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null,local-bounds -mllvm -ubsan-guard-checks -fsanitize-trap=signed-integer-overflow,integer-divide-by-zero,null,local-bounds | FileCheck %s --check-prefixes=TR
4+ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O1 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null,local-bounds -mllvm -ubsan-guard-checks -fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,null,local-bounds | FileCheck %s --check-prefixes=REC
55
66
77// CHECK-LABEL: define dso_local noundef i32 @div(
1818// CHECK: [[HANDLER_DIVREM_OVERFLOW]]:
1919// CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
2020// CHECK-NEXT: [[TMP5:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
21- // CHECK-NEXT: tail call void @__ubsan_handle_divrem_overflow_abort(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR4 :[0-9]+]], !nosanitize [[META2]]
21+ // CHECK-NEXT: tail call void @__ubsan_handle_divrem_overflow_abort(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR6 :[0-9]+]], !nosanitize [[META2]]
2222// CHECK-NEXT: unreachable, !nosanitize [[META2]]
2323// CHECK: [[CONT]]:
2424// CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[Y]]
3636// TR-NEXT: [[DOTNOT1:%.*]] = and i1 [[DOTNOT3]], [[TMP3]]
3737// TR-NEXT: br i1 [[DOTNOT1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]]
3838// TR: [[TRAP]]:
39- // TR-NEXT: tail call void @llvm.ubsantrap(i8 3) #[[ATTR4 :[0-9]+]], !nosanitize [[META2]]
39+ // TR-NEXT: tail call void @llvm.ubsantrap(i8 3) #[[ATTR5 :[0-9]+]], !nosanitize [[META2]]
4040// TR-NEXT: unreachable, !nosanitize [[META2]]
4141// TR: [[CONT]]:
4242// TR-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[Y]]
5656// REC: [[HANDLER_DIVREM_OVERFLOW]]:
5757// REC-NEXT: [[TMP4:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
5858// REC-NEXT: [[TMP5:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
59- // REC-NEXT: tail call void @__ubsan_handle_divrem_overflow(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR4 :[0-9]+]], !nosanitize [[META2]]
59+ // REC-NEXT: tail call void @__ubsan_handle_divrem_overflow(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR6 :[0-9]+]], !nosanitize [[META2]]
6060// REC-NEXT: br label %[[CONT]], !nosanitize [[META2]]
6161// REC: [[CONT]]:
6262// REC-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[Y]]
@@ -74,7 +74,7 @@ int div(int x, int y) {
7474// CHECK-NEXT: [[DOTNOT1:%.*]] = and i1 [[TMP0]], [[TMP1]]
7575// CHECK-NEXT: br i1 [[DOTNOT1]], label %[[HANDLER_TYPE_MISMATCH:.*]], label %[[CONT:.*]], !prof [[PROF3]], !nosanitize [[META2]]
7676// CHECK: [[HANDLER_TYPE_MISMATCH]]:
77- // CHECK-NEXT: tail call void @__ubsan_handle_type_mismatch_v1_abort(ptr nonnull @[[GLOB2:[0-9]+]], i64 0) #[[ATTR4 ]], !nosanitize [[META2]]
77+ // CHECK-NEXT: tail call void @__ubsan_handle_type_mismatch_v1_abort(ptr nonnull @[[GLOB2:[0-9]+]], i64 0) #[[ATTR6 ]], !nosanitize [[META2]]
7878// CHECK-NEXT: unreachable, !nosanitize [[META2]]
7979// CHECK: [[CONT]]:
8080// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA4:![0-9]+]]
@@ -88,7 +88,7 @@ int div(int x, int y) {
8888// TR-NEXT: [[DOTNOT1:%.*]] = and i1 [[TMP0]], [[TMP1]]
8989// TR-NEXT: br i1 [[DOTNOT1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]]
9090// TR: [[TRAP]]:
91- // TR-NEXT: tail call void @llvm.ubsantrap(i8 22) #[[ATTR4 ]], !nosanitize [[META2]]
91+ // TR-NEXT: tail call void @llvm.ubsantrap(i8 22) #[[ATTR5 ]], !nosanitize [[META2]]
9292// TR-NEXT: unreachable, !nosanitize [[META2]]
9393// TR: [[CONT]]:
9494// TR-NEXT: [[TMP2:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA3:![0-9]+]]
@@ -102,7 +102,7 @@ int div(int x, int y) {
102102// REC-NEXT: [[DOTNOT1:%.*]] = and i1 [[TMP0]], [[TMP1]]
103103// REC-NEXT: br i1 [[DOTNOT1]], label %[[HANDLER_TYPE_MISMATCH:.*]], label %[[CONT:.*]], !prof [[PROF3]], !nosanitize [[META2]]
104104// REC: [[HANDLER_TYPE_MISMATCH]]:
105- // REC-NEXT: tail call void @__ubsan_handle_type_mismatch_v1(ptr nonnull @[[GLOB2:[0-9]+]], i64 0) #[[ATTR4 ]], !nosanitize [[META2]]
105+ // REC-NEXT: tail call void @__ubsan_handle_type_mismatch_v1(ptr nonnull @[[GLOB2:[0-9]+]], i64 0) #[[ATTR6 ]], !nosanitize [[META2]]
106106// REC-NEXT: br label %[[CONT]], !nosanitize [[META2]]
107107// REC: [[CONT]]:
108108// REC-NEXT: [[TMP2:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA4:![0-9]+]]
@@ -123,7 +123,7 @@ int null(int* x) {
123123// CHECK: [[HANDLER_ADD_OVERFLOW]]:
124124// CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
125125// CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
126- // CHECK-NEXT: tail call void @__ubsan_handle_add_overflow_abort(ptr nonnull @[[GLOB3:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR4 ]], !nosanitize [[META2]]
126+ // CHECK-NEXT: tail call void @__ubsan_handle_add_overflow_abort(ptr nonnull @[[GLOB3:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR6 ]], !nosanitize [[META2]]
127127// CHECK-NEXT: unreachable, !nosanitize [[META2]]
128128// CHECK: [[CONT]]:
129129// CHECK-NEXT: [[TMP5:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]]
@@ -138,7 +138,7 @@ int null(int* x) {
138138// TR-NEXT: [[DOTDEMORGAN:%.*]] = and i1 [[TMP1]], [[TMP2]]
139139// TR-NEXT: br i1 [[DOTDEMORGAN]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]]
140140// TR: [[TRAP]]:
141- // TR-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR4 ]], !nosanitize [[META2]]
141+ // TR-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR5 ]], !nosanitize [[META2]]
142142// TR-NEXT: unreachable, !nosanitize [[META2]]
143143// TR: [[CONT]]:
144144// TR-NEXT: [[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]]
@@ -155,7 +155,7 @@ int null(int* x) {
155155// REC: [[HANDLER_ADD_OVERFLOW]]:
156156// REC-NEXT: [[TMP3:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
157157// REC-NEXT: [[TMP4:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
158- // REC-NEXT: tail call void @__ubsan_handle_add_overflow(ptr nonnull @[[GLOB3:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR4 ]], !nosanitize [[META2]]
158+ // REC-NEXT: tail call void @__ubsan_handle_add_overflow(ptr nonnull @[[GLOB3:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR6 ]], !nosanitize [[META2]]
159159// REC-NEXT: br label %[[CONT]], !nosanitize [[META2]]
160160// REC: [[CONT]]:
161161// REC-NEXT: [[TMP5:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]]
@@ -164,24 +164,90 @@ int null(int* x) {
164164int overflow (int x , int y ) {
165165 return x + y ;
166166}
167+
168+ void use (double * );
169+
170+ // CHECK-LABEL: define dso_local double @lbounds(
171+ // CHECK-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) local_unnamed_addr #[[ATTR0]] {
172+ // CHECK-NEXT: [[ENTRY:.*:]]
173+ // CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[B]] to i64
174+ // CHECK-NEXT: [[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
175+ // CHECK-NEXT: call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR7:[0-9]+]]
176+ // CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64
177+ // CHECK-NEXT: [[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
178+ // CHECK-NEXT: br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
179+ // CHECK: [[BB1]]:
180+ // CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], i64 [[IDXPROM]]
181+ // CHECK-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa [[TBAA8:![0-9]+]]
182+ // CHECK-NEXT: ret double [[TMP2]]
183+ // CHECK: [[TRAP]]:
184+ // CHECK-NEXT: call void @__ubsan_handle_local_out_of_bounds_abort() #[[ATTR6]]
185+ // CHECK-NEXT: unreachable
186+ //
187+ // TR-LABEL: define dso_local double @lbounds(
188+ // TR-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) local_unnamed_addr #[[ATTR0]] {
189+ // TR-NEXT: [[ENTRY:.*:]]
190+ // TR-NEXT: [[TMP0:%.*]] = zext i32 [[B]] to i64
191+ // TR-NEXT: [[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
192+ // TR-NEXT: call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR6:[0-9]+]]
193+ // TR-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64
194+ // TR-NEXT: [[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
195+ // TR-NEXT: br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
196+ // TR: [[BB1]]:
197+ // TR-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], i64 [[IDXPROM]]
198+ // TR-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa [[TBAA7:![0-9]+]]
199+ // TR-NEXT: ret double [[TMP2]]
200+ // TR: [[TRAP]]:
201+ // TR-NEXT: call void @llvm.ubsantrap(i8 3) #[[ATTR5]]
202+ // TR-NEXT: unreachable
203+ //
204+ // REC-LABEL: define dso_local double @lbounds(
205+ // REC-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) local_unnamed_addr #[[ATTR0]] {
206+ // REC-NEXT: [[ENTRY:.*:]]
207+ // REC-NEXT: [[TMP0:%.*]] = zext i32 [[B]] to i64
208+ // REC-NEXT: [[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
209+ // REC-NEXT: call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR5:[0-9]+]]
210+ // REC-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64
211+ // REC-NEXT: [[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
212+ // REC-NEXT: br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
213+ // REC: [[BB1]]:
214+ // REC-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], i64 [[IDXPROM]]
215+ // REC-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa [[TBAA8:![0-9]+]]
216+ // REC-NEXT: ret double [[TMP2]]
217+ // REC: [[TRAP]]:
218+ // REC-NEXT: call void @__ubsan_handle_local_out_of_bounds() #[[ATTR6]]
219+ // REC-NEXT: br label %[[BB1]]
220+ //
221+ double lbounds (int b , int i ) {
222+ double a [b ];
223+ use (a );
224+ return a [i ];
225+ }
226+
167227//.
168228// CHECK: [[META2]] = !{}
169229// CHECK: [[PROF3]] = !{!"branch_weights", i32 1, i32 1048575}
170230// CHECK: [[TBAA4]] = !{[[META5:![0-9]+]], [[META5]], i64 0}
171231// CHECK: [[META5]] = !{!"int", [[META6:![0-9]+]], i64 0}
172232// CHECK: [[META6]] = !{!"omnipotent char", [[META7:![0-9]+]], i64 0}
173233// CHECK: [[META7]] = !{!"Simple C/C++ TBAA"}
234+ // CHECK: [[TBAA8]] = !{[[META9:![0-9]+]], [[META9]], i64 0}
235+ // CHECK: [[META9]] = !{!"double", [[META6]], i64 0}
174236//.
175237// TR: [[META2]] = !{}
176238// TR: [[TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
177239// TR: [[META4]] = !{!"int", [[META5:![0-9]+]], i64 0}
178240// TR: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0}
179241// TR: [[META6]] = !{!"Simple C/C++ TBAA"}
242+ // TR: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}
243+ // TR: [[META8]] = !{!"double", [[META5]], i64 0}
180244//.
181245// REC: [[META2]] = !{}
182246// REC: [[PROF3]] = !{!"branch_weights", i32 1, i32 1048575}
183247// REC: [[TBAA4]] = !{[[META5:![0-9]+]], [[META5]], i64 0}
184248// REC: [[META5]] = !{!"int", [[META6:![0-9]+]], i64 0}
185249// REC: [[META6]] = !{!"omnipotent char", [[META7:![0-9]+]], i64 0}
186250// REC: [[META7]] = !{!"Simple C/C++ TBAA"}
251+ // REC: [[TBAA8]] = !{[[META9:![0-9]+]], [[META9]], i64 0}
252+ // REC: [[META9]] = !{!"double", [[META6]], i64 0}
187253//.
0 commit comments