[compiler-rt] [compiler-rt][ASan] Remove alignment message in ASan error reporting (PR #94103)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 05:36:22 PDT 2024


https://github.com/AdvenamTacet updated https://github.com/llvm/llvm-project/pull/94103

>From 86ea51fcf7f66170cf5341caea3b17a3ec628a2b Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Sat, 1 Jun 2024 09:29:59 +0200
Subject: [PATCH 1/2] [compiler-rt][ASan] Remove alignment checks in ASan error
 reporting

Removed unnecessary alignment checks in ASan error reporting functions, as alignment is no longer required starting from LLVM 16.

Related commits:
- https://github.com/llvm/llvm-project/commit/dd1b7b797a116eed588fd752fbe61d34deeb24e4
- https://github.com/llvm/llvm-project/commit/1c5ad6d2c01294a0decde43a88e9c27d7437d157
---
 compiler-rt/lib/asan/asan_errors.cpp                  |  4 ----
 .../asan/TestCases/contiguous_container_crash.cpp     | 11 +++++++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp
index 3f2d13e314640..26eabf2400b77 100644
--- a/compiler-rt/lib/asan/asan_errors.cpp
+++ b/compiler-rt/lib/asan/asan_errors.cpp
@@ -328,8 +328,6 @@ void ErrorBadParamsToAnnotateContiguousContainer::Print() {
       "      new_mid : %p\n",
       (void *)beg, (void *)end, (void *)old_mid, (void *)new_mid);
   uptr granularity = ASAN_SHADOW_GRANULARITY;
-  if (!IsAligned(beg, granularity))
-    Report("ERROR: beg is not aligned by %zu\n", granularity);
   stack->Print();
   ReportErrorSummary(scariness.GetDescription(), stack);
 }
@@ -348,8 +346,6 @@ void ErrorBadParamsToAnnotateDoubleEndedContiguousContainer::Print() {
       (void *)old_container_end, (void *)new_container_beg,
       (void *)new_container_end);
   uptr granularity = ASAN_SHADOW_GRANULARITY;
-  if (!IsAligned(storage_beg, granularity))
-    Report("ERROR: storage_beg is not aligned by %zu\n", granularity);
   stack->Print();
   ReportErrorSummary(scariness.GetDescription(), stack);
 }
diff --git a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp
index 41fb2d61a3dec..3560f2066e5ef 100644
--- a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp
+++ b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx_asan -O %s -o %t
 // RUN: not %run %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s
+// RUN: not %run %t unaligned-bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-UNALIGNED-BAD-BOUNDS %s
 // RUN: not %run %t odd-alignment 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: not %run %t odd-alignment-end 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: %env_asan_opts=detect_container_overflow=0 %run %t crash
@@ -35,6 +36,14 @@ void BadBounds() {
                                             &t[0] + 50);
 }
 
+void UnalignedBadBounds() {
+  char t[100];
+  // CHECK-UNALIGNED-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
+  // CHECK-UNALIGNED-BAD-BOUNDS-NOT: beg is not aligned by
+  __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[0] + 101,
+                                            &t[0] + 50);
+}
+
 int OddAlignment() {
   int t[100];
   t[60] = 0;
@@ -57,6 +66,8 @@ int main(int argc, char **argv) {
     return TestCrash();
   else if (!strcmp(argv[1], "bad-bounds"))
     BadBounds();
+  else if (!strcmp(argv[1], "unaligned-bad-bounds"))
+    UnalignedBadBounds();
   else if (!strcmp(argv[1], "odd-alignment"))
     return OddAlignment();
   else if (!strcmp(argv[1], "odd-alignment-end"))

>From 13b2a7e939b5d2fbc0641470b07cef8f65a83203 Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at gmail.com>
Date: Fri, 2 Aug 2024 14:35:59 +0200
Subject: [PATCH 2/2] implicit-check-not

---
 compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp
index 3560f2066e5ef..b88e02b84ad67 100644
--- a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp
+++ b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cpp
@@ -1,7 +1,7 @@
 // RUN: %clangxx_asan -O %s -o %t
 // RUN: not %run %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s
-// RUN: not %run %t unaligned-bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-UNALIGNED-BAD-BOUNDS %s
+// RUN: not %run %t unaligned-bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-UNALIGNED-BAD-BOUNDS %s --implicit-check-not="beg is not aligned by"
 // RUN: not %run %t odd-alignment 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: not %run %t odd-alignment-end 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 // RUN: %env_asan_opts=detect_container_overflow=0 %run %t crash
@@ -39,7 +39,6 @@ void BadBounds() {
 void UnalignedBadBounds() {
   char t[100];
   // CHECK-UNALIGNED-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
-  // CHECK-UNALIGNED-BAD-BOUNDS-NOT: beg is not aligned by
   __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[0] + 101,
                                             &t[0] + 50);
 }



More information about the llvm-commits mailing list