[compiler-rt] bcf2031 - [ubsan] Test CFI summaries globally (#206434)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 31 00:24:50 PDT 2026
Author: Jakob Koschel
Date: 2026-07-31T09:24:44+02:00
New Revision: bcf20310bdafd37253c6c849cd9bd3ba5b79752f
URL: https://github.com/llvm/llvm-project/commit/bcf20310bdafd37253c6c849cd9bd3ba5b79752f
DIFF: https://github.com/llvm/llvm-project/commit/bcf20310bdafd37253c6c849cd9bd3ba5b79752f.diff
LOG: [ubsan] Test CFI summaries globally (#206434)
Always enable report_error_type=1 and print_summary=1 for CFI tests, and
update existing tests to check for cfi-bad-type. This allows us to
verify summary output comprehensively across the test suite.
This is a prerequisite for the change to the UBSan summary for CFI in
https://github.com/llvm/llvm-project/pull/203341.
Assisted-by: Automated tooling, human reviewed.
Added:
Modified:
compiler-rt/test/cfi/anon-namespace.cpp
compiler-rt/test/cfi/bad-cast.cpp
compiler-rt/test/cfi/base-derived-destructor.cpp
compiler-rt/test/cfi/cross-dso-diagnostic.cpp
compiler-rt/test/cfi/cross-dso/icall/diag.cpp
compiler-rt/test/cfi/cross-dso/icall/icall-from-dso.cpp
compiler-rt/test/cfi/cross-dso/icall/icall.cpp
compiler-rt/test/cfi/cross-dso/simple-fail.cpp
compiler-rt/test/cfi/cross-dso/target_out_of_bounds.cpp
compiler-rt/test/cfi/icall/bad-signature.c
compiler-rt/test/cfi/lit.cfg.py
compiler-rt/test/cfi/mfcall.cpp
compiler-rt/test/cfi/multiple-inheritance.cpp
compiler-rt/test/cfi/nvcall.cpp
compiler-rt/test/cfi/overwrite.cpp
compiler-rt/test/cfi/simple-fail.cpp
compiler-rt/test/cfi/target_uninstrumented.cpp
compiler-rt/test/cfi/vdtor.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/cfi/anon-namespace.cpp b/compiler-rt/test/cfi/anon-namespace.cpp
index 2a7ed9c0ac5e7..7ef41f55d84c8 100644
--- a/compiler-rt/test/cfi/anon-namespace.cpp
+++ b/compiler-rt/test/cfi/anon-namespace.cpp
@@ -79,8 +79,10 @@ int main() {
// CFI-DIAG: runtime error: control flow integrity check for type '(anonymous namespace)::B' failed during base-to-derived cast
// CFI-DIAG-NEXT: note: vtable is of type '{{.*}}anonymous namespace{{.*}}::B'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CFI-DIAG: runtime error: control flow integrity check for type '(anonymous namespace)::B' failed during virtual call
// CFI-DIAG-NEXT: note: vtable is of type '{{.*}}anonymous namespace{{.*}}::B'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((B *)a)->f(); // UB here
// CFI-NOT: {{^2$}}
diff --git a/compiler-rt/test/cfi/bad-cast.cpp b/compiler-rt/test/cfi/bad-cast.cpp
index 1c4f19e9e6420..ad3e13313235e 100644
--- a/compiler-rt/test/cfi/bad-cast.cpp
+++ b/compiler-rt/test/cfi/bad-cast.cpp
@@ -100,9 +100,11 @@ int main(int argc, char **argv) {
// CFI-DIAG-D: runtime error: control flow integrity check for type 'B' failed during base-to-derived cast
// CFI-DIAG-D-NEXT: note: vtable is of type '{{(struct )?}}A'
+ // CFI-DIAG-D: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CFI-DIAG-U: runtime error: control flow integrity check for type 'B' failed during cast to unrelated type
// CFI-DIAG-U-NEXT: note: vtable is of type '{{(struct )?}}A'
+ // CFI-DIAG-U: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
switch (argv[1][0]) {
case 'a':
diff --git a/compiler-rt/test/cfi/base-derived-destructor.cpp b/compiler-rt/test/cfi/base-derived-destructor.cpp
index 33c7445d55ea9..e1ece214c5011 100644
--- a/compiler-rt/test/cfi/base-derived-destructor.cpp
+++ b/compiler-rt/test/cfi/base-derived-destructor.cpp
@@ -83,6 +83,7 @@ int main() {
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during base-to-derived cast
// CFI-DIAG-NEXT: note: vtable is of type '{{(class )?}}A<{{(class )?}}B>'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
B* b = new B;
break_optimization(b);
delete b; // UB here
diff --git a/compiler-rt/test/cfi/cross-dso-diagnostic.cpp b/compiler-rt/test/cfi/cross-dso-diagnostic.cpp
index 9d0e077a7eaf7..7e5e645e0bce7 100644
--- a/compiler-rt/test/cfi/cross-dso-diagnostic.cpp
+++ b/compiler-rt/test/cfi/cross-dso-diagnostic.cpp
@@ -35,11 +35,13 @@ int main() {
// CHECK: runtime error: control flow integrity check for type 'void *()' failed during indirect function call
// CHECK: cross-dso-diagnostic.cpp:[[@LINE-13]]: note: dso_symbol defined here
// CHECK: check failed in {{.*}}_exe_suffix, destination function located in {{.*}}[[DSONAME]]
+ // CHECK: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
void *S = fp(); // trigger cfi-icall failure
// CHECK: runtime error: control flow integrity check for type 'S1' failed during cast to unrelated type
// CHECK: invalid vtable
// CHECK: check failed in {{.*}}_exe_suffix, vtable located in {{.*}}[[DSONAME]]
+ // CHECK: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
S1 *Scast = reinterpret_cast<S1*>(S); // trigger cfi-unrelated-cast failure
return 0;
diff --git a/compiler-rt/test/cfi/cross-dso/icall/diag.cpp b/compiler-rt/test/cfi/cross-dso/icall/diag.cpp
index fadbdefd066ce..c3472f9bdaa3b 100644
--- a/compiler-rt/test/cfi/cross-dso/icall/diag.cpp
+++ b/compiler-rt/test/cfi/cross-dso/icall/diag.cpp
@@ -114,6 +114,7 @@ int main(int argc, char *argv[]) {
if (argv[1][0] == 'i') {
// ICALL-DIAG: runtime error: control flow integrity check for type 'void *(int)' failed during indirect function call
// ICALL-DIAG-NEXT: dynamic.so+0x{{[[:xdigit:]]+}}): note: create_B() {{(\(.cfi_jt\) )?}}defined here
+ // ICALL-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// ICALL-NODIAG-NOT: runtime error: control flow integrity check {{.*}} during indirect function call
p = ((void *(*)(int))create_B)(42);
} else {
@@ -130,6 +131,7 @@ int main(int argc, char *argv[]) {
if (argv[1][1] == 'c') {
// CAST-DIAG: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
// CAST-DIAG-NEXT: note: vtable is of type '{{(struct )?}}B'
+ // CAST-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CAST-NODIAG-NOT: runtime error: control flow integrity check {{.*}} during cast to unrelated type
a = (A*)p;
} else {
@@ -145,6 +147,7 @@ int main(int argc, char *argv[]) {
// VCALL-DIAG: runtime error: control flow integrity check for type 'A' failed during virtual call
// VCALL-DIAG-NEXT: note: vtable is of type '{{(struct )?}}B'
+ // VCALL-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// VCALL-NODIAG-NOT: runtime error: control flow integrity check {{.*}} during virtual call
if (argv[1][2] == 'v') {
a->f(); // UB here
diff --git a/compiler-rt/test/cfi/cross-dso/icall/icall-from-dso.cpp b/compiler-rt/test/cfi/cross-dso/icall/icall-from-dso.cpp
index 3364d54fdfadb..eb8364b0699ac 100644
--- a/compiler-rt/test/cfi/cross-dso/icall/icall-from-dso.cpp
+++ b/compiler-rt/test/cfi/cross-dso/icall/icall-from-dso.cpp
@@ -19,6 +19,7 @@ void f() {
fprintf(stderr, "=2=\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
// CFI-DIAG-NEXT: ({{.*}}exe+0x{{[[:xdigit:]]+}}): note: g() {{(\(.cfi_jt\) )?}}defined here
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((void (*)(int))g)(42); // UB here
// CHECK-DIAG: =3=
// CHECK-NOT: =3=
diff --git a/compiler-rt/test/cfi/cross-dso/icall/icall.cpp b/compiler-rt/test/cfi/cross-dso/icall/icall.cpp
index 671d6f1d7fdb7..5ad3d0d2faa5c 100644
--- a/compiler-rt/test/cfi/cross-dso/icall/icall.cpp
+++ b/compiler-rt/test/cfi/cross-dso/icall/icall.cpp
@@ -22,6 +22,7 @@ int main() {
fprintf(stderr, "=2=\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
// CFI-DIAG-NEXT: ({{.*}}dynamic.so+0x{{[[:xdigit:]]+}}): note: f() {{(\(.cfi_jt\) )?}}defined here
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((void (*)(int))f)(42); // UB here
// CHECK-DIAG: =3=
// CHECK-NOT: =3=
diff --git a/compiler-rt/test/cfi/cross-dso/simple-fail.cpp b/compiler-rt/test/cfi/cross-dso/simple-fail.cpp
index 91ce45a6130c4..68176803b2c73 100644
--- a/compiler-rt/test/cfi/cross-dso/simple-fail.cpp
+++ b/compiler-rt/test/cfi/cross-dso/simple-fail.cpp
@@ -79,6 +79,7 @@ int main(int argc, char *argv[]) {
// Test cast. BOOM.
// CFI-DIAG-CAST: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
// CFI-DIAG-CAST-NEXT: note: vtable is of type '{{(struct )?}}B'
+ // CFI-DIAG-CAST: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
a = (A*)p;
} else {
// Invisible to CFI. Test virtual call later.
@@ -92,6 +93,7 @@ int main(int argc, char *argv[]) {
// CFI-DIAG-CALL: runtime error: control flow integrity check for type 'A' failed during virtual call
// CFI-DIAG-CALL-NEXT: note: vtable is of type '{{(struct )?}}B'
+ // CFI-DIAG-CALL: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
a->f(); // UB here
// CFI-NOT: =2=
diff --git a/compiler-rt/test/cfi/cross-dso/target_out_of_bounds.cpp b/compiler-rt/test/cfi/cross-dso/target_out_of_bounds.cpp
index 80b736e2c91cd..fb5bb458dcceb 100644
--- a/compiler-rt/test/cfi/cross-dso/target_out_of_bounds.cpp
+++ b/compiler-rt/test/cfi/cross-dso/target_out_of_bounds.cpp
@@ -37,9 +37,11 @@ int main(int argc, char *argv[]) {
// CHECK-UNADDR: runtime error: control flow integrity check for type 'A' failed during cast
// CHECK-UNADDR: note: invalid vtable
// CHECK-UNADDR: <memory cannot be printed>
+ // CHECK-UNADDR: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CHECK-UNADDR: runtime error: control flow integrity check for type 'A' failed during cast
// CHECK-UNADDR: note: invalid vtable
// CHECK-UNADDR: <memory cannot be printed>
+ // CHECK-UNADDR: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
} else if (argc > 1 && strcmp(argv[1], "zero") == 0) {
// Create an object with a vtable outside of any known DSO, but still in an
// addressable area.
@@ -48,9 +50,11 @@ int main(int argc, char *argv[]) {
// CHECK-ZERO: runtime error: control flow integrity check for type 'A' failed during cast
// CHECK-ZERO: note: invalid vtable
// CHECK-ZERO: 00 00 00 00 00 00 00 00
+ // CHECK-ZERO: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CHECK-ZERO: runtime error: control flow integrity check for type 'A' failed during cast
// CHECK-ZERO: note: invalid vtable
// CHECK-ZERO: 00 00 00 00 00 00 00 00
+ // CHECK-ZERO: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
} else {
// Create an object with a seemingly fine vtable, but with an unaddressable
// typeinfo pointer.
@@ -60,9 +64,11 @@ int main(int argc, char *argv[]) {
// CHECK-TYPEINFO: runtime error: control flow integrity check for type 'A' failed during cast
// CHECK-TYPEINFO: note: invalid vtable
// CHECK-TYPEINFO: fe fe fe fe fe fe fe fe
+ // CHECK-TYPEINFO: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CHECK-TYPEINFO: runtime error: control flow integrity check for type 'A' failed during cast
// CHECK-TYPEINFO: note: invalid vtable
// CHECK-TYPEINFO: fe fe fe fe fe fe fe fe
+ // CHECK-TYPEINFO: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
}
A *volatile pa = reinterpret_cast<A *>(p);
diff --git a/compiler-rt/test/cfi/icall/bad-signature.c b/compiler-rt/test/cfi/icall/bad-signature.c
index 93f2c5797bda6..68ba19e5ef4c8 100644
--- a/compiler-rt/test/cfi/icall/bad-signature.c
+++ b/compiler-rt/test/cfi/icall/bad-signature.c
@@ -18,6 +18,7 @@ int main() {
// CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
// CFI-DIAG: bad-signature.c:[[@LINE-8]]{{(:[0-9]+)?}}: note: f defined here
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((void (*)(int))f)(42); // UB here
// CFI-NOT: 2
diff --git a/compiler-rt/test/cfi/lit.cfg.py b/compiler-rt/test/cfi/lit.cfg.py
index c879d7f46e6be..ee8a2a5983b37 100644
--- a/compiler-rt/test/cfi/lit.cfg.py
+++ b/compiler-rt/test/cfi/lit.cfg.py
@@ -63,8 +63,12 @@ def build_invocation(compile_flags):
else:
config.unsupported = True
-if config.default_sanitizer_opts:
- config.environment["UBSAN_OPTIONS"] = ":".join(config.default_sanitizer_opts)
+default_ubsan_opts = (
+ list(config.default_sanitizer_opts) if config.default_sanitizer_opts else []
+)
+default_ubsan_opts.append("print_summary=1")
+default_ubsan_opts.append("report_error_type=1")
+config.environment["UBSAN_OPTIONS"] = ":".join(default_ubsan_opts)
if lit_config.params.get("check_supported", None) and config.unsupported:
raise BaseException("Tests unsupported")
diff --git a/compiler-rt/test/cfi/mfcall.cpp b/compiler-rt/test/cfi/mfcall.cpp
index f95251f5adb44..104bad09547c0 100644
--- a/compiler-rt/test/cfi/mfcall.cpp
+++ b/compiler-rt/test/cfi/mfcall.cpp
@@ -64,26 +64,31 @@ int main(int argc, char **argv) {
case 'a':
// A: runtime error: control flow integrity check for type 'int (S::*)()' failed during non-virtual pointer to member function call
// A: note: S::f1() {{.*}}defined here
+ // A: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
(s.*bitcast<S_int>(&S::f1))();
break;
case 'b':
// B: runtime error: control flow integrity check for type 'int (T::*)()' failed during non-virtual pointer to member function call
// B: note: S::f2() {{.*}}defined here
+ // B: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
(t.*bitcast<T_int>(&S::f2))();
break;
case 'c':
// C: runtime error: control flow integrity check for type 'int (S::*)()' failed during virtual pointer to member function call
// C: note: vtable is of type 'S'
+ // C: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
(s.*bitcast<S_int>(&S::g1))();
break;
case 'd':
// D: runtime error: control flow integrity check for type 'int (S::*)()' failed during virtual pointer to member function call
// D: note: vtable is of type 'T'
+ // D: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
(reinterpret_cast<S &>(t).*&S::g2)();
break;
case 'e':
// E: runtime error: control flow integrity check for type 'void (S::*)()' failed during virtual pointer to member function call
// E: note: vtable is of type 'S'
+ // E: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
(s.*bitcast<S_void>(&T::g3))();
break;
case 'f':
diff --git a/compiler-rt/test/cfi/multiple-inheritance.cpp b/compiler-rt/test/cfi/multiple-inheritance.cpp
index b8520d8b08b10..84ce8619f412e 100644
--- a/compiler-rt/test/cfi/multiple-inheritance.cpp
+++ b/compiler-rt/test/cfi/multiple-inheritance.cpp
@@ -60,10 +60,12 @@ int main(int argc, char **argv) {
A *a = c;
// CFI-DIAG1: runtime error: control flow integrity check for type 'B' failed during cast to unrelated type
// CFI-DIAG1-NEXT: note: vtable is of type '{{(struct )?}}C'
+ // CFI-DIAG1: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((B *)a)->g(); // UB here
} else {
// CFI-DIAG2: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
// CFI-DIAG2-NEXT: note: vtable is of type '{{(struct )?}}C'
+ // CFI-DIAG2: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
B *b = c;
((A *)b)->f(); // UB here
}
diff --git a/compiler-rt/test/cfi/nvcall.cpp b/compiler-rt/test/cfi/nvcall.cpp
index b61adb1fed064..2ad50823fb619 100644
--- a/compiler-rt/test/cfi/nvcall.cpp
+++ b/compiler-rt/test/cfi/nvcall.cpp
@@ -51,6 +51,7 @@ int main() {
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during non-virtual call
// CFI-DIAG-NEXT: note: vtable is of type '{{(struct )?}}A'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((B *)a)->f(); // UB here
// CFI-NOT: {{^2$}}
diff --git a/compiler-rt/test/cfi/overwrite.cpp b/compiler-rt/test/cfi/overwrite.cpp
index 7d7ad1c77f0cb..7b089a70e8978 100644
--- a/compiler-rt/test/cfi/overwrite.cpp
+++ b/compiler-rt/test/cfi/overwrite.cpp
@@ -53,6 +53,7 @@ int main() {
// NCFI: foo
// CFI-DIAG: runtime error: control flow integrity check for type 'A' failed during virtual call
// CFI-DIAG-NEXT: note: invalid vtable
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
a->f();
// We don't check for the absence of a 2 here because under devirtualization
diff --git a/compiler-rt/test/cfi/simple-fail.cpp b/compiler-rt/test/cfi/simple-fail.cpp
index ef36fb08ab4e0..7da02c75d1096 100644
--- a/compiler-rt/test/cfi/simple-fail.cpp
+++ b/compiler-rt/test/cfi/simple-fail.cpp
@@ -91,8 +91,10 @@ int main() {
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during cast to unrelated type
// CFI-DIAG-NEXT: note: vtable is of type '{{(struct )?}}A'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during virtual call
// CFI-DIAG-NEXT: note: vtable is of type '{{(struct )?}}A'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
((B *)a)->f(); // UB here
// CFI-NOT: {{^2$}}
diff --git a/compiler-rt/test/cfi/target_uninstrumented.cpp b/compiler-rt/test/cfi/target_uninstrumented.cpp
index d92cb4cf61ff0..578dafc072372 100644
--- a/compiler-rt/test/cfi/target_uninstrumented.cpp
+++ b/compiler-rt/test/cfi/target_uninstrumented.cpp
@@ -35,12 +35,14 @@ int main(int argc, char *argv[]) {
// CHECK: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
// CHECK: invalid vtable
// CHECK: check failed in {{.*}}, vtable located in {{.*}}libtarget_uninstrumented.cpp.dynamic.so
+ // CHECK: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
A *a = (A *)p;
memset(p, 0, sizeof(A));
// CHECK: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
// CHECK: invalid vtable
// CHECK: check failed in {{.*}}, vtable located in (unknown)
+ // CHECK: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
a = (A *)p;
// CHECK: done
fprintf(stderr, "done %p\n", a);
diff --git a/compiler-rt/test/cfi/vdtor.cpp b/compiler-rt/test/cfi/vdtor.cpp
index defa4ce15f50e..1d90653b061f0 100644
--- a/compiler-rt/test/cfi/vdtor.cpp
+++ b/compiler-rt/test/cfi/vdtor.cpp
@@ -48,6 +48,7 @@ int main() {
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during virtual call
// CFI-DIAG-NEXT: note: vtable is of type '{{(struct )?}}A'
+ // CFI-DIAG: SUMMARY: UndefinedBehaviorSanitizer: cfi-bad-type
delete (B *)a; // UB here
// CFI-NOT: {{^2$}}
More information about the llvm-commits
mailing list