[compiler-rt] 5db1f54 - compiler-rt: ubsan: Add suppressions test for nested functions (#206962)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 03:42:45 PDT 2026


Author: maflcko
Date: 2026-07-13T12:42:40+02:00
New Revision: 5db1f5442ef0c9bcb2f4ca362361daaf2a76acfb

URL: https://github.com/llvm/llvm-project/commit/5db1f5442ef0c9bcb2f4ca362361daaf2a76acfb
DIFF: https://github.com/llvm/llvm-project/commit/5db1f5442ef0c9bcb2f4ca362361daaf2a76acfb.diff

LOG: compiler-rt: ubsan: Add suppressions test for nested functions (#206962)

This is a test-only change to increase the test coverage of UBSan to
clarify that named suppressions only apply to the function itself and do
not cover (possibly inlined) called functions.

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 case that I
broke, which serves as a reference baseline ground truth.

---------

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_ at 721217.xyz>

Added: 
    compiler-rt/test/ubsan/TestCases/Integer/Inputs/make_signed.h
    compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
    compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls.c

Modified: 
    

Removed: 
    


################################################################################
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 
diff erent 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..85f7d57620c92
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Integer/Inputs/wrappers.h
@@ -0,0 +1,17 @@
+#ifndef TEST__WRAPPERS_H
+#define TEST__WRAPPERS_H
+
+#include "make_signed.h"
+
+int my_wrapper(unsigned a) {
+  // direct wrapper
+  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.c b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls.c
new file mode 100644
index 0000000000000..487d35eaa83f4
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Integer/suppressions-nested-calls.c
@@ -0,0 +1,50 @@
+// REQUIRES: can-symbolize
+// UNSUPPORTED: android
+
+// # Test for UBSan suppressions with nested function calls
+//
+// RUN: %clang -fsanitize=integer -O0 -g %s -o %t.o0
+//
+// # 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: echo "implicit-integer-sign-change:Inputs/make_signed.h" > %t.make_signed.file.supp
+//
+// RUN: %env_ubsan_opts=suppressions='"%t.make_signed.name.supp"' %run %t.o0 2>&1 | FileCheck %s --check-prefix=CHECK-MAKE-SIGNED
+// RUN: %env_ubsan_opts=suppressions='"%t.make_signed.file.supp"' %run %t.o0 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.my_wrapper_2.name.supp
+// RUN: echo "implicit-integer-sign-change:Inputs/wrappers.h" > %t.wrappers.file.supp
+//
+// RUN: %env_ubsan_opts=suppressions='"%t.my_wrapper_2.name.supp"' %run %t.o0 2>&1 | FileCheck %s --check-prefix=CHECK-WRAPPERS
+// RUN: %env_ubsan_opts=suppressions='"%t.wrappers.file.supp"'     %run %t.o0 2>&1 | FileCheck %s --check-prefix=CHECK-WRAPPERS
+//
+// # Suppress both.
+// RUN: cat %t.make_signed.name.supp %t.my_wrapper_2.name.supp > %t.both.name.supp
+// RUN: cat %t.make_signed.file.supp %t.wrappers.file.supp > %t.both.file.supp
+//
+// RUN: %env_ubsan_opts=suppressions='"%t.both.name.supp"' %run %t.o0 2>&1 | FileCheck %s --allow-empty --check-prefix=CHECK-BOTH
+// RUN: %env_ubsan_opts=suppressions='"%t.both.file.supp"' %run %t.o0 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: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
+// 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