[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:23:08 PDT 2026


https://github.com/maflcko created https://github.com/llvm/llvm-project/pull/206962

This is a test-only change to increase the test coverage of UBSan under `-finline` and `-fno-inline`.

The background is that, while trying to fix https://github.com/llvm/llvm-project/issues/132533, I discovered missing test coverage and possibly confused myself into a wrong fix in https://github.com/llvm/llvm-project/pull/206735#discussion_r3505816693

So I think it could make sense to add test coverage for the `-fno-inline` case here, which serves as a reference baseline ground truth. Also, there is an almost-identical corresponding test case for `-finline`, which spells out the current differences.

>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] 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:



More information about the llvm-commits mailing list