-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[TySan] Improved compatability for tests #96507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TySan] Improved compatability for tests #96507
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@fhahn (Sorry for the ping, I can't manually add reviewers yet) |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: None (gbMattN) ChangesAll the violation tests failed when running on my machine. By changing some check lines to regular expressions, we can account for file locality, and hardware specific type differences. There was also an include needed for better integer types. Full diff: https://github.com/llvm/llvm-project/pull/96507.diff 6 Files Affected:
diff --git a/compiler-rt/test/tysan/violation-pr45282.c b/compiler-rt/test/tysan/violation-pr45282.c
index 2cbc37b3d1832..37e710ae18deb 100644
--- a/compiler-rt/test/tysan/violation-pr45282.c
+++ b/compiler-rt/test/tysan/violation-pr45282.c
@@ -18,7 +18,7 @@ int main(void) {
// CHECK: TypeSanitizer: type-aliasing-violation on address
// CHECK-NEXT: WRITE of size 8 at {{.+}} with type double accesses an existing object of type float
-// CHECK-NEXT: in main violation-pr45282.c:25
+// CHECK-NEXT: in main {{.*violation-pr45282.c:25.*}}
// loop of problems
for (j = 2; j <= 4; ++j) {
diff --git a/compiler-rt/test/tysan/violation-pr47137.c b/compiler-rt/test/tysan/violation-pr47137.c
index 04d68d1dd936e..7b996d39f81e2 100644
--- a/compiler-rt/test/tysan/violation-pr47137.c
+++ b/compiler-rt/test/tysan/violation-pr47137.c
@@ -4,6 +4,7 @@
// https://github.com/llvm/llvm-project/issues/47137
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
void f(int m) {
int n = (4 * m + 2) / 3;
@@ -23,8 +24,8 @@ void f(int m) {
}
// CHECK: TypeSanitizer: type-aliasing-violation on address
-// CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type long long
-// CHECK-NEXT: in f violation-pr47137.c:30
+// CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type {{(long)+}}
+// CHECK-NEXT: in f {{.*violation-pr47137.c:31.*}}
for (int i = 0, j = 0; j < 4 * m; i += 4, j += 3) {
for (int k = 0; k < 3; k++) {
((uint16_t *)a)[j + k] = ((uint16_t *)a)[i + k];
diff --git a/compiler-rt/test/tysan/violation-pr62544.c b/compiler-rt/test/tysan/violation-pr62544.c
index 4187a91bde3fc..7c6cb59156d15 100644
--- a/compiler-rt/test/tysan/violation-pr62544.c
+++ b/compiler-rt/test/tysan/violation-pr62544.c
@@ -18,7 +18,7 @@ int main() {
// CHECK: TypeSanitizer: type-aliasing-violation on address
// CHECK-NEXT: WRITE of size 2 at {{.+}} with type short accesses an existing object of type int
-// CHECK-NEXT: in main violation-pr62544.c:22
+// CHECK-NEXT: in main {{.*violation-pr62544.c:22.*}}
*e = 3;
printf("%d\n", a);
}
diff --git a/compiler-rt/test/tysan/violation-pr62828.cpp b/compiler-rt/test/tysan/violation-pr62828.cpp
index 879200c8069b0..f815227d86248 100644
--- a/compiler-rt/test/tysan/violation-pr62828.cpp
+++ b/compiler-rt/test/tysan/violation-pr62828.cpp
@@ -24,7 +24,7 @@ short *test1(int_v8 *cast_c_array, short_v8 *shuf_c_array1, int *ptr) {
// CHECK: ERROR: TypeSanitizer: type-aliasing-violation on address
// CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type int
-// CHECK-NEXT: in test1(int (*) [8], short (*) [8], int*) violation-pr62828.cpp:29
+// CHECK-NEXT: in test1(int (*) [8], short (*) [8], int*) {{.*violation-pr62828.cpp:29.*}}
for (int i3 = 0; i3 < 4; ++i3) {
output2[i3] = input2[(i3 * 2)];
}
diff --git a/compiler-rt/test/tysan/violation-pr68655.cpp b/compiler-rt/test/tysan/violation-pr68655.cpp
index ac20f8c94e1ff..615971c75d20e 100644
--- a/compiler-rt/test/tysan/violation-pr68655.cpp
+++ b/compiler-rt/test/tysan/violation-pr68655.cpp
@@ -9,7 +9,7 @@ struct S1 {
// CHECK: TypeSanitizer: type-aliasing-violation on address
// CHECK-NEXT: READ of size 4 at {{.+}} with type int accesses an existing object of type long long (in S1 at offset 0)
-// CHECK-NEXT: in copyMem(S1*, S1*) violation-pr68655.cpp:19
+// CHECK-NEXT: in copyMem(S1*, S1*) {{.*violation-pr68655.cpp:19.*}}
void inline copyMem(S1 *dst, S1 *src) {
unsigned *d = reinterpret_cast<unsigned *>(dst);
diff --git a/compiler-rt/test/tysan/violation-pr86685.c b/compiler-rt/test/tysan/violation-pr86685.c
index b5198c440fa44..6667fc1805195 100644
--- a/compiler-rt/test/tysan/violation-pr86685.c
+++ b/compiler-rt/test/tysan/violation-pr86685.c
@@ -13,7 +13,7 @@ void foo(int *s, float *f, long n) {
// CHECK: TypeSanitizer: type-aliasing-violation on address
// CHECK-NEXT: WRITE of size 4 at {{.+}} with type int accesses an existing object of type float
-// CHECK-NEXT: #0 {{.+}} in foo violation-pr86685.c:17
+// CHECK-NEXT: #0 {{.+}} in foo {{.*violation-pr86685.c:17.*}}
*s = 4;
}
}
|
e2caf4e
to
733b3ed
Compare
712aa7f
to
9df832f
Compare
@fhahn updated to remove merge conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable enough to me, I'm far from a tysan expert, but I requested review for you. 👍
// CHECK: TypeSanitizer: type-aliasing-violation on address | ||
// CHECK-NEXT: WRITE of size 8 at {{.+}} with type double accesses an existing object of type float | ||
// CHECK-NEXT: in main violation-pr45282.c:25 | ||
// CHECK-NEXT: in main {{.*violation-pr45282.c:25.*}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: IMO having {{.*}}
to swallow extra path components is slightly preferable, as that avoids the filename being part of a regex. Almost certainly not ever going to be a problem, but it reduces what can go wrong. Does your environment also have trailing components after the line number? If there's any whitespace between '5' and the extra text then FileCheck will (99% confident) ignore those anyway.
Similar thoughts apply to all the other similar regexes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked and the trailing .* can indeed be left out, I'll change that
Compiler-rt tests tend to have the file name in the check lines because you want to make sure that the sanitizer correctly informs the user where the problem is.
// CHECK: TypeSanitizer: type-aliasing-violation on address | ||
// CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type long long | ||
// CHECK-NEXT: in f violation-pr47137.c:30 | ||
// CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type {{(long)+}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO having an optional (with ?
) long is preferable to having an unbound number of longs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, will change that 👍
9df832f
to
c684ebd
Compare
733b3ed
to
8e6e62d
Compare
c684ebd
to
11c62d6
Compare
You can test this locally with the following command:git-clang-format --diff 8e6e62d0dee48a696afd0c7d53d74eaccef97b5e 11c62d601626d9da1fb3ed0c9cadab2d106681ab --extensions cpp,c -- compiler-rt/test/tysan/violation-pr45282.c compiler-rt/test/tysan/violation-pr47137.c compiler-rt/test/tysan/violation-pr62544.c compiler-rt/test/tysan/violation-pr62828.cpp compiler-rt/test/tysan/violation-pr68655.cpp compiler-rt/test/tysan/violation-pr86685.c View the diff from clang-format here.diff --git a/compiler-rt/test/tysan/violation-pr47137.c b/compiler-rt/test/tysan/violation-pr47137.c
index 72693afe66..e488c23fe1 100644
--- a/compiler-rt/test/tysan/violation-pr47137.c
+++ b/compiler-rt/test/tysan/violation-pr47137.c
@@ -2,9 +2,9 @@
// RUN: FileCheck %s < %t.out
// https://github.com/llvm/llvm-project/issues/47137
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
void f(int m) {
int n = (4 * m + 2) / 3;
|
5c0e520
to
6f48a28
Compare
Sorry I didn't mean to close this PR, looks like it happened automatically once I deleted the |
All the violation tests failed when running on my machine. This was due to changes in file structure, and my machine using different underlying types for types like uint64_t. By changing some check lines to regular expressions, we can account for file locality, and hardware specific type differences. There was also an include needed for better integer types.