[compiler-rt] compiler-rt: ubsan: Add suppressions test for inlined functions (PR #206962)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 05:50:52 PDT 2026
https://github.com/maflcko updated https://github.com/llvm/llvm-project/pull/206962
>From fab11a2ac602645bb14a41ccea1f09a17462fb7b Mon Sep 17 00:00:00 2001
From: MarcoFalke <*~=`'#}+{/-|&$^_ at 721217.xyz>
Date: Wed, 1 Jul 2026 14:16:02 +0200
Subject: [PATCH 1/2] compiler-rt: ubsan: Add suppressions test for inlined
functions
---
.../TestCases/Integer/Inputs/make_signed.h | 13 ++++
.../ubsan/TestCases/Integer/Inputs/wrappers.h | 16 +++++
.../suppressions-nested-calls-inline.c | 68 +++++++++++++++++++
.../suppressions-nested-calls-no-inline.c | 58 ++++++++++++++++
4 files changed, 155 insertions(+)
create mode 100644 compiler-rt/test/ubsan/TestCases/Integer/Inputs/make_signed.h
create mode 100644 compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
create mode 100644 compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c
create mode 100644 compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/Inputs/make_signed.h b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/make_signed.h
new file mode 100644
index 0000000000000..f5e1db098368a
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/make_signed.h
@@ -0,0 +1,13 @@
+#ifndef TEST__MAKE_SIGNED_H
+#define TEST__MAKE_SIGNED_H
+
+static int my_make_signed(unsigned a) {
+ // Use different return paths so each report location can be distinguished.
+ if (a < 4002222222U)
+ return a;
+ if (a < 4003333333U)
+ return a;
+ return a;
+}
+
+#endif
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
new file mode 100644
index 0000000000000..31fdf451ec4c1
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
@@ -0,0 +1,16 @@
+#ifndef TEST__WRAPPERS_H
+#define TEST__WRAPPERS_H
+
+#include "make_signed.h"
+
+int my_wrapper(unsigned a) {
+ return my_make_signed(a);
+}
+
+int my_wrapper_2(unsigned a) {
+ volatile int test = a;
+ (void)test;
+ return my_make_signed(a);
+}
+
+#endif
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c
new file mode 100644
index 0000000000000..a60b76e351ce8
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c
@@ -0,0 +1,68 @@
+// REQUIRES: can-symbolize
+// UNSUPPORTED: android
+
+// # Companion test for UBSan suppressions with -finline.
+// # This variant intentionally differs from the -fno-inline baseline.
+//
+// RUN: %clang -fsanitize=integer -fsanitize-recover=integer -O1 -finline -g %s -o %t
+//
+// # Only the directly suppressed my_make_signed hit should disappear.
+//
+// RUN: echo "implicit-integer-sign-change:my_make_signed" > %t.make_signed.name.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.make_signed.name.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MAKE-SIGNED-INLINE-NAME
+// RUN: echo "implicit-integer-sign-change:Inputs/make_signed.h" > %t.make_signed.file.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.make_signed.file.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MAKE-SIGNED
+//
+// # Only the suppressed wrapper-originated hit should disappear.
+//
+// RUN: echo "implicit-integer-sign-change:my_wrapper_2" > %t.wrapper_2.name.supp
+// RUN: echo "implicit-integer-sign-change:my_wrapper" > %t.wrapper.name.supp
+// RUN: cat %t.wrapper.name.supp %t.wrapper_2.name.supp > %t.wrappers.name.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.wrappers.name.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WRAPPERS
+// RUN: echo "implicit-integer-sign-change:Inputs/wrappers.h" > %t.wrappers.file.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.wrappers.file.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WRAPPERS
+//
+// # Suppress both.
+//
+// RUN: cat %t.make_signed.name.supp %t.wrapper_2.name.supp > %t.both.name.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.both.name.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH-INLINE-NAME
+// RUN: cat %t.make_signed.file.supp %t.wrappers.file.supp > %t.both.file.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.both.file.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-BOTH
+
+#include "Inputs/make_signed.h"
+#include "Inputs/wrappers.h"
+
+int main(void) {
+ volatile unsigned a1 = 4001111111U;
+ volatile unsigned a2 = 4002222222U;
+ volatile unsigned a3 = 4003333333U;
+ int r1 = my_make_signed(a1);
+ int r2 = my_wrapper(a2);
+ int r3 = my_wrapper_2(a3);
+ return 0;
+}
+
+// The inlined my_make_signed call still produces a report under name-based
+// suppression.
+// CHECK-MAKE-SIGNED-INLINE-NAME: {{.*}}wrappers.h:11:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-MAKE-SIGNED-INLINE-NAME: {{.*}}make_signed.h:10:10: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+
+// CHECK-MAKE-SIGNED: {{.*}}wrappers.h:11:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-MAKE-SIGNED-NOT: make_signed.h:{{.*}}runtime error:
+
+// CHECK-WRAPPERS: {{.*}}make_signed.h:7:12: runtime error: implicit conversion from type 'unsigned int' of value 4001111111
+// CHECK-WRAPPERS: {{.*}}make_signed.h:9:12: runtime error: implicit conversion from type 'unsigned int' of value 4002222222
+// CHECK-WRAPPERS: {{.*}}make_signed.h:10:10: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-WRAPPERS-NOT: {{.*}}wrappers.h:{{.*}}runtime error:
+
+// The inlined my_make_signed call still produces a report under name-based
+// suppression.
+// CHECK-BOTH-INLINE-NAME: {{.*}}make_signed.h:10:10: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+
+// CHECK-BOTH-NOT: runtime error:
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c
new file mode 100644
index 0000000000000..63aa9cf2eafe9
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c
@@ -0,0 +1,58 @@
+// REQUIRES: can-symbolize
+// UNSUPPORTED: android
+
+// # Baseline test for UBSan suppressions with -fno-inline.
+//
+// RUN: %clang -fsanitize=integer -fsanitize-recover=integer -O1 -fno-inline -g %s -o %t
+//
+// # Only the directly suppressed my_make_signed hit should disappear.
+//
+// RUN: echo "implicit-integer-sign-change:my_make_signed" > %t.make_signed.name.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.make_signed.name.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MAKE-SIGNED
+// RUN: echo "implicit-integer-sign-change:Inputs/make_signed.h" > %t.make_signed.file.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.make_signed.file.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MAKE-SIGNED
+//
+// # Only the suppressed wrapper-originated hit should disappear.
+//
+// RUN: echo "implicit-integer-sign-change:my_wrapper_2" > %t.wrapper_2.name.supp
+// RUN: echo "implicit-integer-sign-change:my_wrapper" > %t.wrapper.name.supp
+// RUN: cat %t.wrapper.name.supp %t.wrapper_2.name.supp > %t.wrappers.name.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.wrappers.name.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WRAPPERS
+// RUN: echo "implicit-integer-sign-change:Inputs/wrappers.h" > %t.wrappers.file.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.wrappers.file.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WRAPPERS
+//
+// # Suppress both.
+//
+// RUN: cat %t.make_signed.name.supp %t.wrapper_2.name.supp > %t.both.name.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.both.name.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-BOTH
+// RUN: cat %t.make_signed.file.supp %t.wrappers.file.supp > %t.both.file.supp
+// RUN: %env_ubsan_opts=report_error_type=1:print_stacktrace=1:suppressions='"%t.both.file.supp"' \
+// RUN: %run %t 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-BOTH
+
+#include "Inputs/make_signed.h"
+#include "Inputs/wrappers.h"
+
+int main(void) {
+ volatile unsigned a1 = 4001111111U;
+ volatile unsigned a2 = 4002222222U;
+ volatile unsigned a3 = 4003333333U;
+ int r1 = my_make_signed(a1);
+ int r2 = my_wrapper(a2);
+ int r3 = my_wrapper_2(a3);
+ return 0;
+}
+
+// CHECK-MAKE-SIGNED: {{.*}}wrappers.h:11:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-MAKE-SIGNED-NOT: make_signed.h:{{.*}}runtime error:
+
+// CHECK-WRAPPERS: {{.*}}make_signed.h:7:12: runtime error: implicit conversion from type 'unsigned int' of value 4001111111
+// CHECK-WRAPPERS: {{.*}}make_signed.h:9:12: runtime error: implicit conversion from type 'unsigned int' of value 4002222222
+// CHECK-WRAPPERS: {{.*}}make_signed.h:10:10: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-WRAPPERS-NOT: {{.*}}wrappers.h:{{.*}}runtime error:
+
+// CHECK-BOTH-NOT: runtime error:
>From 6d4aa65176ea51286b711c067f73d2c4dd79bfb9 Mon Sep 17 00:00:00 2001
From: MarcoFalke <*~=`'#}+{/-|&$^_ at 721217.xyz>
Date: Wed, 1 Jul 2026 14:50:30 +0200
Subject: [PATCH 2/2] clang format
---
compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h | 1 +
.../TestCases/Integer/suppressions-nested-calls-inline.c | 4 ++--
.../TestCases/Integer/suppressions-nested-calls-no-inline.c | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
index 31fdf451ec4c1..85f7d57620c92 100644
--- a/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
+++ b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
@@ -4,6 +4,7 @@
#include "make_signed.h"
int my_wrapper(unsigned a) {
+ // direct wrapper
return my_make_signed(a);
}
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c
index a60b76e351ce8..09eceb7c50a18 100644
--- a/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c
+++ b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-inline.c
@@ -50,10 +50,10 @@ int main(void) {
// The inlined my_make_signed call still produces a report under name-based
// suppression.
-// CHECK-MAKE-SIGNED-INLINE-NAME: {{.*}}wrappers.h:11:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-MAKE-SIGNED-INLINE-NAME: {{.*}}wrappers.h:12:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
// CHECK-MAKE-SIGNED-INLINE-NAME: {{.*}}make_signed.h:10:10: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
-// CHECK-MAKE-SIGNED: {{.*}}wrappers.h:11:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-MAKE-SIGNED: {{.*}}wrappers.h:12:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
// CHECK-MAKE-SIGNED-NOT: make_signed.h:{{.*}}runtime error:
// CHECK-WRAPPERS: {{.*}}make_signed.h:7:12: runtime error: implicit conversion from type 'unsigned int' of value 4001111111
diff --git a/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c
index 63aa9cf2eafe9..7ace8f5b56623 100644
--- a/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c
+++ b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls-no-inline.c
@@ -47,7 +47,7 @@ int main(void) {
return 0;
}
-// CHECK-MAKE-SIGNED: {{.*}}wrappers.h:11:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
+// CHECK-MAKE-SIGNED: {{.*}}wrappers.h:12:23: runtime error: implicit conversion from type 'unsigned int' of value 4003333333
// CHECK-MAKE-SIGNED-NOT: make_signed.h:{{.*}}runtime error:
// CHECK-WRAPPERS: {{.*}}make_signed.h:7:12: runtime error: implicit conversion from type 'unsigned int' of value 4001111111
More information about the llvm-commits
mailing list