From 40d72d9a1f28d6bbbe2a8a2a5314e42029a83b0f Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Wed, 25 Feb 2015 17:03:34 +0000 Subject: [PATCH] Reland r230019 - [ASan] Make the argument of '__sanitizer_annotate_contiguous_container' is not aligned error message easier to understand This incorporates the fix for ARM architecture suggested by Renato Golin. llvm-svn: 230506 --- compiler-rt/lib/asan/asan_report.cc | 3 +++ .../test/asan/TestCases/contiguous_container_crash.cc | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 8706d5d..ad75262 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -834,6 +834,9 @@ void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end, " old_mid : %p\n" " new_mid : %p\n", beg, end, old_mid, new_mid); + uptr granularity = SHADOW_GRANULARITY; + if (!IsAligned(beg, granularity)) + Report("ERROR: beg is not aligned by %d\n", granularity); stack->Print(); ReportErrorSummary("bad-__sanitizer_annotate_contiguous_container", stack); } diff --git a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc index 143ae9d..9bea177 100644 --- a/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc +++ b/compiler-rt/test/asan/TestCases/contiguous_container_crash.cc @@ -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 %s +// RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s +// RUN: not %run %t bad-alignment 2>&1 | FileCheck --check-prefix=CHECK-BAD-ALIGNMENT %s // RUN: env ASAN_OPTIONS=detect_container_overflow=0 %run %t crash // // Test crash due to __sanitizer_annotate_contiguous_container. @@ -21,21 +22,31 @@ int TestCrash() { t[60] = 0; __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100, &t[0] + 50); +// CHECK-CRASH: AddressSanitizer: container-overflow return (int)t[60 * one]; // Touches the poisoned memory. } void BadBounds() { long t[100]; +// CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101, &t[0] + 50); } +void BadAlignment() { + int t[100]; +// CHECK-BAD-ALIGNMENT: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container +// CHECK-BAD-ALIGNMENT: ERROR: beg is not aligned by 8 + __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[1] + 10, + &t[0] + 50); +} + int main(int argc, char **argv) { assert(argc == 2); if (!strcmp(argv[1], "crash")) return TestCrash(); else if (!strcmp(argv[1], "bad-bounds")) BadBounds(); + else if (!strcmp(argv[1], "bad-alignment")) + BadAlignment(); } -// CHECK-CRASH: AddressSanitizer: container-overflow -// CHECK-BAD: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container -- 2.7.4