[compiler-rt] [cfi][test] use more robust test patterns (PR #165982)
Maxim Zhukov via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 1 02:06:30 PDT 2025
https://github.com/Mephistophiles created https://github.com/llvm/llvm-project/pull/165982
When test output contains extra data (such as debug logs), tests can become flaky if there are strings like '12':
the problem is that after successfully finding '1' in '12', the pattern '^2$' will find a full match in '2' following '1' (mentioned in #165899).
To prevent this, use patterns that search for '1' or '2' as standalone strings on their own line.
>From ff8b32999947548df6a618d5d2d0007c35f78fb4 Mon Sep 17 00:00:00 2001
From: Maxim Zhukov <mussitantesmortem at gmail.com>
Date: Sat, 1 Nov 2025 12:00:52 +0300
Subject: [PATCH] [cfi][test] use more robust test patterns
When test output contains extra data (such as debug logs), tests can
become flaky if there are strings like '12':
the problem is that after successfully finding '1' in '12', the pattern
'^2$' will find a full match in '2' following '1' (mentioned in #165899).
To prevent this, use patterns that search for '1' or '2' as standalone
strings on their own line.
---
compiler-rt/test/cfi/anon-namespace.cpp | 4 ++--
compiler-rt/test/cfi/bad-cast.cpp | 4 ++--
compiler-rt/test/cfi/base-derived-destructor.cpp | 4 ++--
compiler-rt/test/cfi/icall/bad-signature.c | 8 ++++----
compiler-rt/test/cfi/icall/external-call.c | 4 ++--
compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c | 4 ++--
compiler-rt/test/cfi/multiple-inheritance.cpp | 4 ++--
compiler-rt/test/cfi/nvcall.cpp | 4 ++--
compiler-rt/test/cfi/overwrite.cpp | 4 ++--
compiler-rt/test/cfi/sibling.cpp | 8 ++++----
compiler-rt/test/cfi/simple-fail.cpp | 4 ++--
compiler-rt/test/cfi/vdtor.cpp | 4 ++--
12 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/compiler-rt/test/cfi/anon-namespace.cpp b/compiler-rt/test/cfi/anon-namespace.cpp
index 2a7ed9c0ac5e7..f9a6459e5fa71 100644
--- a/compiler-rt/test/cfi/anon-namespace.cpp
+++ b/compiler-rt/test/cfi/anon-namespace.cpp
@@ -73,8 +73,8 @@ int main() {
A *a = mkb();
break_optimization(a);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type '(anonymous namespace)::B' failed during base-to-derived cast
diff --git a/compiler-rt/test/cfi/bad-cast.cpp b/compiler-rt/test/cfi/bad-cast.cpp
index 1c4f19e9e6420..f7e6d31f96432 100644
--- a/compiler-rt/test/cfi/bad-cast.cpp
+++ b/compiler-rt/test/cfi/bad-cast.cpp
@@ -92,8 +92,8 @@ int main(int argc, char **argv) {
B *b = new B;
break_optimization(b);
- // FAIL: 1
- // PASS: 1
+ // FAIL: {{^1$}}
+ // PASS: {{^1$}}
fprintf(stderr, "1\n");
A a;
diff --git a/compiler-rt/test/cfi/base-derived-destructor.cpp b/compiler-rt/test/cfi/base-derived-destructor.cpp
index 33c7445d55ea9..15785133d5ad1 100644
--- a/compiler-rt/test/cfi/base-derived-destructor.cpp
+++ b/compiler-rt/test/cfi/base-derived-destructor.cpp
@@ -77,8 +77,8 @@ class B : public A<B> {
};
int main() {
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during base-to-derived cast
diff --git a/compiler-rt/test/cfi/icall/bad-signature.c b/compiler-rt/test/cfi/icall/bad-signature.c
index 183e62738bb26..d662ef9569420 100644
--- a/compiler-rt/test/cfi/icall/bad-signature.c
+++ b/compiler-rt/test/cfi/icall/bad-signature.c
@@ -13,15 +13,15 @@ void f() {
}
int main() {
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
// CFI-DIAG: f defined here
((void (*)(int))f)(42); // UB here
- // CFI-NOT: 2
- // NCFI: 2
+ // CFI-NOT: {{^2$}}
+ // NCFI: {{^2$}}
fprintf(stderr, "2\n");
}
diff --git a/compiler-rt/test/cfi/icall/external-call.c b/compiler-rt/test/cfi/icall/external-call.c
index 27c4478781645..a321cdb910b30 100644
--- a/compiler-rt/test/cfi/icall/external-call.c
+++ b/compiler-rt/test/cfi/icall/external-call.c
@@ -12,7 +12,7 @@
#include <math.h>
int main(int argc, char **argv) {
- // CFI: 1
+ // CFI: {{^1$}}
fprintf(stderr, "1\n");
double (*fn)(double);
@@ -23,6 +23,6 @@ int main(int argc, char **argv) {
fn(atof(argv[2]));
- // CFI: 2
+ // CFI: {{^2$}}
fprintf(stderr, "2\n");
}
diff --git a/compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c b/compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c
index 0e5fb8508c900..ece17040541c2 100644
--- a/compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c
+++ b/compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c
@@ -29,13 +29,13 @@ int f() {
void f();
int main() {
- // CFI: 1
+ // CFI: {{^1$}}
fprintf(stderr, "1\n");
void (*volatile p)() = &f;
p();
- // CFI-NOT: 2
+ // CFI-NOT: {{^2$}}
fprintf(stderr, "2\n");
}
#endif
diff --git a/compiler-rt/test/cfi/multiple-inheritance.cpp b/compiler-rt/test/cfi/multiple-inheritance.cpp
index b8520d8b08b10..2db750dd85fe1 100644
--- a/compiler-rt/test/cfi/multiple-inheritance.cpp
+++ b/compiler-rt/test/cfi/multiple-inheritance.cpp
@@ -52,8 +52,8 @@ int main(int argc, char **argv) {
C *c = new C;
break_optimization(c);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
if (argc > 1) {
diff --git a/compiler-rt/test/cfi/nvcall.cpp b/compiler-rt/test/cfi/nvcall.cpp
index b61adb1fed064..cebfab865f909 100644
--- a/compiler-rt/test/cfi/nvcall.cpp
+++ b/compiler-rt/test/cfi/nvcall.cpp
@@ -45,8 +45,8 @@ int main() {
A *a = new A;
break_optimization(a);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during non-virtual call
diff --git a/compiler-rt/test/cfi/overwrite.cpp b/compiler-rt/test/cfi/overwrite.cpp
index 7d7ad1c77f0cb..0ccaedaaf7950 100644
--- a/compiler-rt/test/cfi/overwrite.cpp
+++ b/compiler-rt/test/cfi/overwrite.cpp
@@ -45,8 +45,8 @@ int main() {
*((void **)a) = fake_vtable + 2; // UB here
break_optimization(a);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-NOT: foo
diff --git a/compiler-rt/test/cfi/sibling.cpp b/compiler-rt/test/cfi/sibling.cpp
index fb6e2f295ff32..40faa79787c06 100644
--- a/compiler-rt/test/cfi/sibling.cpp
+++ b/compiler-rt/test/cfi/sibling.cpp
@@ -42,13 +42,13 @@ int main() {
B *b = new B;
break_optimization(b);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
((C *)b)->f(); // UB here
- // CFI-NOT: 2
- // NCFI: 2
+ // CFI-NOT: {{^2$}}
+ // NCFI: {{^2$}}
fprintf(stderr, "2\n");
}
diff --git a/compiler-rt/test/cfi/simple-fail.cpp b/compiler-rt/test/cfi/simple-fail.cpp
index ef36fb08ab4e0..f178de6705c98 100644
--- a/compiler-rt/test/cfi/simple-fail.cpp
+++ b/compiler-rt/test/cfi/simple-fail.cpp
@@ -85,8 +85,8 @@ int main() {
A *a = new A;
break_optimization(a);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during cast to unrelated type
diff --git a/compiler-rt/test/cfi/vdtor.cpp b/compiler-rt/test/cfi/vdtor.cpp
index defa4ce15f50e..2c073496d4ae0 100644
--- a/compiler-rt/test/cfi/vdtor.cpp
+++ b/compiler-rt/test/cfi/vdtor.cpp
@@ -42,8 +42,8 @@ int main() {
A *a = new A;
break_optimization(a);
- // CFI: 1
- // NCFI: 1
+ // CFI: {{^1$}}
+ // NCFI: {{^1$}}
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during virtual call
More information about the llvm-commits
mailing list