-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nfc][ubsan] Add local-bounds test #122415
base: users/vitalybuka/spr/main.nfcubsan-add-local-bounds-test
Are you sure you want to change the base?
[nfc][ubsan] Add local-bounds test #122415
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) ChangesShow that @llvm.allow.ubsan.check is not used yet. Full diff: https://github.com/llvm/llvm-project/pull/122415.diff 1 Files Affected:
diff --git a/clang/test/CodeGen/allow-ubsan-check.c b/clang/test/CodeGen/allow-ubsan-check.c
index 76dd9f653309cb..2c4e10080df2c3 100644
--- a/clang/test/CodeGen/allow-ubsan-check.c
+++ b/clang/test/CodeGen/allow-ubsan-check.c
@@ -1,7 +1,7 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O3 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm -ubsan-guard-checks | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O3 -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=TRAP
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O3 -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=RECOVER
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O3 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,local-bounds -mllvm -ubsan-guard-checks | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O3 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,local-bounds -mllvm -ubsan-guard-checks -fsanitize-trap=signed-integer-overflow,integer-divide-by-zero,local-bounds | FileCheck %s --check-prefixes=TRAP
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -O3 -o - %s -fsanitize=signed-integer-overflow,integer-divide-by-zero,local-bounds -mllvm -ubsan-guard-checks -fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,local-bounds | FileCheck %s --check-prefixes=RECOVER
// CHECK-LABEL: define dso_local noundef i32 @div(
@@ -18,7 +18,7 @@
// CHECK: [[HANDLER_DIVREM_OVERFLOW]]:
// CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
// CHECK-NEXT: [[TMP5:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
-// CHECK-NEXT: tail call void @__ubsan_handle_divrem_overflow_abort(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR4:[0-9]+]], !nosanitize [[META2]]
+// CHECK-NEXT: tail call void @__ubsan_handle_divrem_overflow_abort(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR7:[0-9]+]], !nosanitize [[META2]]
// CHECK-NEXT: unreachable, !nosanitize [[META2]]
// CHECK: [[CONT]]:
// CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[Y]]
@@ -36,7 +36,7 @@
// TRAP-NEXT: [[DOTNOT1:%.*]] = and i1 [[DOTNOT3]], [[TMP3]]
// TRAP-NEXT: br i1 [[DOTNOT1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]]
// TRAP: [[TRAP]]:
-// TRAP-NEXT: tail call void @llvm.ubsantrap(i8 3) #[[ATTR4:[0-9]+]], !nosanitize [[META2]]
+// TRAP-NEXT: tail call void @llvm.ubsantrap(i8 3) #[[ATTR6:[0-9]+]], !nosanitize [[META2]]
// TRAP-NEXT: unreachable, !nosanitize [[META2]]
// TRAP: [[CONT]]:
// TRAP-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[Y]]
@@ -56,7 +56,7 @@
// RECOVER: [[HANDLER_DIVREM_OVERFLOW]]:
// RECOVER-NEXT: [[TMP4:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
// RECOVER-NEXT: [[TMP5:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
-// RECOVER-NEXT: tail call void @__ubsan_handle_divrem_overflow(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR4:[0-9]+]], !nosanitize [[META2]]
+// RECOVER-NEXT: tail call void @__ubsan_handle_divrem_overflow(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[TMP4]], i64 [[TMP5]]) #[[ATTR7:[0-9]+]], !nosanitize [[META2]]
// RECOVER-NEXT: br label %[[CONT]], !nosanitize [[META2]]
// RECOVER: [[CONT]]:
// RECOVER-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[Y]]
@@ -67,46 +67,22 @@ int div(int x, int y) {
}
// CHECK-LABEL: define dso_local i32 @null(
-// CHECK-SAME: ptr noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-SAME: ptr nocapture noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] {
// CHECK-NEXT: [[ENTRY:.*:]]
-// CHECK-NEXT: [[TMP0:%.*]] = icmp eq ptr [[X]], null, !nosanitize [[META2]]
-// CHECK-NEXT: [[TMP1:%.*]] = tail call i1 @llvm.allow.ubsan.check(i8 22), !nosanitize [[META2]]
-// CHECK-NEXT: [[DOTNOT1:%.*]] = and i1 [[TMP0]], [[TMP1]]
-// CHECK-NEXT: br i1 [[DOTNOT1]], label %[[HANDLER_TYPE_MISMATCH:.*]], label %[[CONT:.*]], !prof [[PROF3]], !nosanitize [[META2]]
-// CHECK: [[HANDLER_TYPE_MISMATCH]]:
-// CHECK-NEXT: tail call void @__ubsan_handle_type_mismatch_v1_abort(ptr nonnull @[[GLOB2:[0-9]+]], i64 0) #[[ATTR4]], !nosanitize [[META2]]
-// CHECK-NEXT: unreachable, !nosanitize [[META2]]
-// CHECK: [[CONT]]:
-// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA4:![0-9]+]]
-// CHECK-NEXT: ret i32 [[TMP2]]
+// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA4:![0-9]+]]
+// CHECK-NEXT: ret i32 [[TMP0]]
//
// TRAP-LABEL: define dso_local i32 @null(
-// TRAP-SAME: ptr noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// TRAP-SAME: ptr nocapture noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] {
// TRAP-NEXT: [[ENTRY:.*:]]
-// TRAP-NEXT: [[TMP0:%.*]] = icmp eq ptr [[X]], null, !nosanitize [[META2]]
-// TRAP-NEXT: [[TMP1:%.*]] = tail call i1 @llvm.allow.ubsan.check(i8 22), !nosanitize [[META2]]
-// TRAP-NEXT: [[DOTNOT1:%.*]] = and i1 [[TMP0]], [[TMP1]]
-// TRAP-NEXT: br i1 [[DOTNOT1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]]
-// TRAP: [[TRAP]]:
-// TRAP-NEXT: tail call void @llvm.ubsantrap(i8 22) #[[ATTR4]], !nosanitize [[META2]]
-// TRAP-NEXT: unreachable, !nosanitize [[META2]]
-// TRAP: [[CONT]]:
-// TRAP-NEXT: [[TMP2:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA3:![0-9]+]]
-// TRAP-NEXT: ret i32 [[TMP2]]
+// TRAP-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA3:![0-9]+]]
+// TRAP-NEXT: ret i32 [[TMP0]]
//
// RECOVER-LABEL: define dso_local i32 @null(
-// RECOVER-SAME: ptr noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// RECOVER-SAME: ptr nocapture noundef readonly [[X:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] {
// RECOVER-NEXT: [[ENTRY:.*:]]
-// RECOVER-NEXT: [[TMP0:%.*]] = icmp eq ptr [[X]], null, !nosanitize [[META2]]
-// RECOVER-NEXT: [[TMP1:%.*]] = tail call i1 @llvm.allow.ubsan.check(i8 22), !nosanitize [[META2]]
-// RECOVER-NEXT: [[DOTNOT1:%.*]] = and i1 [[TMP0]], [[TMP1]]
-// RECOVER-NEXT: br i1 [[DOTNOT1]], label %[[HANDLER_TYPE_MISMATCH:.*]], label %[[CONT:.*]], !prof [[PROF3]], !nosanitize [[META2]]
-// RECOVER: [[HANDLER_TYPE_MISMATCH]]:
-// RECOVER-NEXT: tail call void @__ubsan_handle_type_mismatch_v1(ptr nonnull @[[GLOB2:[0-9]+]], i64 0) #[[ATTR4]], !nosanitize [[META2]]
-// RECOVER-NEXT: br label %[[CONT]], !nosanitize [[META2]]
-// RECOVER: [[CONT]]:
-// RECOVER-NEXT: [[TMP2:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA4:![0-9]+]]
-// RECOVER-NEXT: ret i32 [[TMP2]]
+// RECOVER-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 4, !tbaa [[TBAA4:![0-9]+]]
+// RECOVER-NEXT: ret i32 [[TMP0]]
//
int null(int* x) {
return *x;
@@ -123,7 +99,7 @@ int null(int* x) {
// CHECK: [[HANDLER_ADD_OVERFLOW]]:
// CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
// CHECK-NEXT: [[TMP4:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
-// CHECK-NEXT: tail call void @__ubsan_handle_add_overflow_abort(ptr nonnull @[[GLOB3:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR4]], !nosanitize [[META2]]
+// CHECK-NEXT: tail call void @__ubsan_handle_add_overflow_abort(ptr nonnull @[[GLOB2:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR7]], !nosanitize [[META2]]
// CHECK-NEXT: unreachable, !nosanitize [[META2]]
// CHECK: [[CONT]]:
// CHECK-NEXT: [[TMP5:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]]
@@ -138,7 +114,7 @@ int null(int* x) {
// TRAP-NEXT: [[DOTDEMORGAN:%.*]] = and i1 [[TMP1]], [[TMP2]]
// TRAP-NEXT: br i1 [[DOTDEMORGAN]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]]
// TRAP: [[TRAP]]:
-// TRAP-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR4]], !nosanitize [[META2]]
+// TRAP-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR6]], !nosanitize [[META2]]
// TRAP-NEXT: unreachable, !nosanitize [[META2]]
// TRAP: [[CONT]]:
// TRAP-NEXT: [[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]]
@@ -155,7 +131,7 @@ int null(int* x) {
// RECOVER: [[HANDLER_ADD_OVERFLOW]]:
// RECOVER-NEXT: [[TMP3:%.*]] = zext i32 [[X]] to i64, !nosanitize [[META2]]
// RECOVER-NEXT: [[TMP4:%.*]] = zext i32 [[Y]] to i64, !nosanitize [[META2]]
-// RECOVER-NEXT: tail call void @__ubsan_handle_add_overflow(ptr nonnull @[[GLOB3:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR4]], !nosanitize [[META2]]
+// RECOVER-NEXT: tail call void @__ubsan_handle_add_overflow(ptr nonnull @[[GLOB2:[0-9]+]], i64 [[TMP3]], i64 [[TMP4]]) #[[ATTR7]], !nosanitize [[META2]]
// RECOVER-NEXT: br label %[[CONT]], !nosanitize [[META2]]
// RECOVER: [[CONT]]:
// RECOVER-NEXT: [[TMP5:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]]
@@ -164,6 +140,67 @@ int null(int* x) {
int overflow(int x, int y) {
return x + y;
}
+
+void use(double*);
+
+// CHECK-LABEL: define dso_local double @f1(
+// CHECK-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[B]] to i64
+// CHECK-NEXT: [[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
+// CHECK-NEXT: call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR8:[0-9]+]]
+// CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64
+// CHECK-NEXT: [[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
+// CHECK-NEXT: br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
+// CHECK: [[BB1]]:
+// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], i64 [[IDXPROM]]
+// CHECK-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa [[TBAA8:![0-9]+]]
+// CHECK-NEXT: ret double [[TMP2]]
+// CHECK: [[TRAP]]:
+// CHECK-NEXT: call void @__ubsan_handle_local_out_of_bounds_abort() #[[ATTR7]]
+// CHECK-NEXT: unreachable
+//
+// TRAP-LABEL: define dso_local double @f1(
+// TRAP-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// TRAP-NEXT: [[ENTRY:.*:]]
+// TRAP-NEXT: [[TMP0:%.*]] = zext i32 [[B]] to i64
+// TRAP-NEXT: [[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
+// TRAP-NEXT: call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR7:[0-9]+]]
+// TRAP-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64
+// TRAP-NEXT: [[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
+// TRAP-NEXT: br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
+// TRAP: [[BB1]]:
+// TRAP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], i64 [[IDXPROM]]
+// TRAP-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa [[TBAA7:![0-9]+]]
+// TRAP-NEXT: ret double [[TMP2]]
+// TRAP: [[TRAP]]:
+// TRAP-NEXT: call void @llvm.ubsantrap(i8 3) #[[ATTR6]]
+// TRAP-NEXT: unreachable
+//
+// RECOVER-LABEL: define dso_local double @f1(
+// RECOVER-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// RECOVER-NEXT: [[ENTRY:.*:]]
+// RECOVER-NEXT: [[TMP0:%.*]] = zext i32 [[B]] to i64
+// RECOVER-NEXT: [[VLA:%.*]] = alloca double, i64 [[TMP0]], align 16
+// RECOVER-NEXT: call void @use(ptr noundef nonnull [[VLA]]) #[[ATTR6:[0-9]+]]
+// RECOVER-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64
+// RECOVER-NEXT: [[DOTNOT:%.*]] = icmp ugt i64 [[TMP0]], [[IDXPROM]]
+// RECOVER-NEXT: br i1 [[DOTNOT]], label %[[BB1:.*]], label %[[TRAP:.*]]
+// RECOVER: [[BB1]]:
+// RECOVER-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[VLA]], i64 [[IDXPROM]]
+// RECOVER-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa [[TBAA8:![0-9]+]]
+// RECOVER-NEXT: ret double [[TMP2]]
+// RECOVER: [[TRAP]]:
+// RECOVER-NEXT: call void @__ubsan_handle_local_out_of_bounds() #[[ATTR7]]
+// RECOVER-NEXT: br label %[[BB1]]
+//
+double f1(int b, int i) {
+ double a[b];
+ use(a);
+ return a[i];
+}
+
+
//.
// CHECK: [[META2]] = !{}
// CHECK: [[PROF3]] = !{!"branch_weights", i32 1, i32 1048575}
@@ -171,12 +208,16 @@ int overflow(int x, int y) {
// CHECK: [[META5]] = !{!"int", [[META6:![0-9]+]], i64 0}
// CHECK: [[META6]] = !{!"omnipotent char", [[META7:![0-9]+]], i64 0}
// CHECK: [[META7]] = !{!"Simple C/C++ TBAA"}
+// CHECK: [[TBAA8]] = !{[[META9:![0-9]+]], [[META9]], i64 0}
+// CHECK: [[META9]] = !{!"double", [[META6]], i64 0}
//.
// TRAP: [[META2]] = !{}
// TRAP: [[TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
// TRAP: [[META4]] = !{!"int", [[META5:![0-9]+]], i64 0}
// TRAP: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0}
// TRAP: [[META6]] = !{!"Simple C/C++ TBAA"}
+// TRAP: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}
+// TRAP: [[META8]] = !{!"double", [[META5]], i64 0}
//.
// RECOVER: [[META2]] = !{}
// RECOVER: [[PROF3]] = !{!"branch_weights", i32 1, i32 1048575}
@@ -184,4 +225,6 @@ int overflow(int x, int y) {
// RECOVER: [[META5]] = !{!"int", [[META6:![0-9]+]], i64 0}
// RECOVER: [[META6]] = !{!"omnipotent char", [[META7:![0-9]+]], i64 0}
// RECOVER: [[META7]] = !{!"Simple C/C++ TBAA"}
+// RECOVER: [[TBAA8]] = !{[[META9:![0-9]+]], [[META9]], i64 0}
+// RECOVER: [[META9]] = !{!"double", [[META6]], i64 0}
//.
|
Looks like update_cc_test_checks is being confused if it creates vars with the name matching prefix. Issue triggered with #122415
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to keep -fsanitize=...null and add local-bounds instead of replacing null with local-bounds? It would make the test more rigorous and also make the diff smaller.
edit: or is it not possible to make a test case that is local-bounds sanitized where null sanitization does not apply?
Show that @llvm.allow.ubsan.check is not used yet.