Skip to content

Conversation

Cao-Wuhui
Copy link
Contributor

Reland of #161624, depends on revert #162001. NFC: test-only.

  • Android: keep %env_asan_opts=log_to_stderr=1 to route the ASan header to stderr.
  • Darwin: use a DAG group for the two potentially reordered lines:
    • // CHECK-DAG: Good so far.
    • // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:...]] at pc {{...}} bp {{...}} sp {{...}}
  • Then enforce strict order:
    • // CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
    • // CHECK: #0 {{0x[0-9a-f]+}} in <func>

…droid (test-only)

Reland of llvm#161624; depends on revert llvm#162001.

- Android: keep %env_asan_opts=log_to_stderr=1.
- Darwin: use CHECK-DAG for the pre-crash marker and header; frame line matches function only.
- Common: reuse [[ADDR]].

NFC: test-only.

Signed-off-by: Yixuan Cao <caoyixuan2019@email.szu.edu.cn>
@llvmbot
Copy link
Member

llvmbot commented Oct 5, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Yixuan Cao (Cao-Wuhui)

Changes

Reland of #161624, depends on revert #162001. NFC: test-only.

  • Android: keep %env_asan_opts=log_to_stderr=1 to route the ASan header to stderr.
  • Darwin: use a DAG group for the two potentially reordered lines:
    • // CHECK-DAG: Good so far.
    • // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:...]] at pc {{...}} bp {{...}} sp {{...}}
  • Then enforce strict order:
    • // CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
    • // CHECK: #<!-- -->0 {{0x[0-9a-f]+}} in &lt;func&gt;

Full diff: https://github.com/llvm/llvm-project/pull/162002.diff

4 Files Affected:

  • (modified) compiler-rt/test/asan/TestCases/wcscat.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/wcscpy.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/wcsncat.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/wcsncpy.cpp (+2-2)
diff --git a/compiler-rt/test/asan/TestCases/wcscat.cpp b/compiler-rt/test/asan/TestCases/wcscat.cpp
index f0a8ec12580b3..1dde1262cd0f3 100644
--- a/compiler-rt/test/asan/TestCases/wcscat.cpp
+++ b/compiler-rt/test/asan/TestCases/wcscat.cpp
@@ -16,10 +16,10 @@ int main() {
   wchar_t badDst[9];
   wcscpy(badDst, start);
   fprintf(stderr, "Good so far.\n");
-  // CHECK: Good so far.
+  // CHECK-DAG: Good so far.
   fflush(stderr);
   wcscat(badDst, append); // Boom!
-  // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
+  // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
   // CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
   // CHECK: #0 {{0x[0-9a-f]+}} in wcscat
   printf("Should have failed with ASAN error.\n");
diff --git a/compiler-rt/test/asan/TestCases/wcscpy.cpp b/compiler-rt/test/asan/TestCases/wcscpy.cpp
index a280d29289e37..2553e428e5464 100644
--- a/compiler-rt/test/asan/TestCases/wcscpy.cpp
+++ b/compiler-rt/test/asan/TestCases/wcscpy.cpp
@@ -13,10 +13,10 @@ int main() {
 
   wchar_t badDst[7];
   fprintf(stderr, "Good so far.\n");
-  // CHECK: Good so far.
+  // CHECK-DAG: Good so far.
   fflush(stderr);
   wcscpy(badDst, src); // Boom!
-  // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
+  // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
   // CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
   // CHECK: #0 {{0x[0-9a-f]+}} in wcscpy
   printf("Should have failed with ASAN error.\n");
diff --git a/compiler-rt/test/asan/TestCases/wcsncat.cpp b/compiler-rt/test/asan/TestCases/wcsncat.cpp
index eb7d095e45c7a..fdf4247532e45 100644
--- a/compiler-rt/test/asan/TestCases/wcsncat.cpp
+++ b/compiler-rt/test/asan/TestCases/wcsncat.cpp
@@ -17,10 +17,10 @@ int main() {
   wcscpy(badDst, start);
   wcsncat(badDst, append, 1);
   fprintf(stderr, "Good so far.\n");
-  // CHECK: Good so far.
+  // CHECK-DAG: Good so far.
   fflush(stderr);
   wcsncat(badDst, append, 3); // Boom!
-  // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
+  // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
   // CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
   // CHECK: #0 {{0x[0-9a-f]+}} in wcsncat
   printf("Should have failed with ASAN error.\n");
diff --git a/compiler-rt/test/asan/TestCases/wcsncpy.cpp b/compiler-rt/test/asan/TestCases/wcsncpy.cpp
index 1106bf5d264e5..70824e0d06c5a 100644
--- a/compiler-rt/test/asan/TestCases/wcsncpy.cpp
+++ b/compiler-rt/test/asan/TestCases/wcsncpy.cpp
@@ -14,11 +14,11 @@ int main() {
   wchar_t badDst[7];
   wcsncpy(badDst, src, 7); // This should still work.
   fprintf(stderr, "Good so far.\n");
-  // CHECK: Good so far.
+  // CHECK-DAG: Good so far.
   fflush(stderr);
 
   wcsncpy(badDst, src, 15); // Boom!
-  // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
+  // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
   // CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
   // CHECK: #0 {{0x[0-9a-f]+}} in wcsncpy
   printf("Should have failed with ASAN error.\n");

@Cao-Wuhui
Copy link
Contributor Author

I have opened a new PR #162028 because this PR was out-of-date.

@Cao-Wuhui Cao-Wuhui closed this Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants