[compiler-rt] e37f8e5 - [test][asan] Simplify __sanitizer_verify_contiguous_container test
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 19 01:52:34 PST 2022
Author: Vitaly Buka
Date: 2022-11-19T01:52:22-08:00
New Revision: e37f8e588cd8a1d89f6cfbb829b8c9b6d8014b0f
URL: https://github.com/llvm/llvm-project/commit/e37f8e588cd8a1d89f6cfbb829b8c9b6d8014b0f
DIFF: https://github.com/llvm/llvm-project/commit/e37f8e588cd8a1d89f6cfbb829b8c9b6d8014b0f.diff
LOG: [test][asan] Simplify __sanitizer_verify_contiguous_container test
Added:
Modified:
compiler-rt/test/asan/TestCases/contiguous_container.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/asan/TestCases/contiguous_container.cpp b/compiler-rt/test/asan/TestCases/contiguous_container.cpp
index d78678069672..d6ec5230a99f 100644
--- a/compiler-rt/test/asan/TestCases/contiguous_container.cpp
+++ b/compiler-rt/test/asan/TestCases/contiguous_container.cpp
@@ -48,23 +48,31 @@ void TestContainer(size_t capacity, size_t off_begin, bool poison_buffer) {
// bytes after the end.
for (; cur != end + kGranularity; ++cur)
assert(__asan_address_is_poisoned(cur) == poison_buffer);
- assert(__sanitizer_verify_contiguous_container(beg, mid, end));
- assert(NULL ==
- __sanitizer_contiguous_container_find_bad_address(beg, mid, end));
- size_t distance = (end > RoundDown(end)) ? kGranularity + 1 : 1;
- if (mid >= beg + distance) {
- assert(
- !__sanitizer_verify_contiguous_container(beg, mid - distance, end));
- assert(mid - distance ==
- __sanitizer_contiguous_container_find_bad_address(
- beg, mid - distance, end));
- }
+ }
+
+ for (int i = 0; i <= capacity; i++) {
+ old_mid = mid;
+ mid = beg + i;
+ __sanitizer_annotate_contiguous_container(beg, end, old_mid, mid);
- if (mid + distance <= end) {
- assert(
- !__sanitizer_verify_contiguous_container(beg, mid + distance, end));
- assert(mid == __sanitizer_contiguous_container_find_bad_address(
- beg, mid + distance, end));
+ for (char *cur = std::max(beg, mid - 2 * kGranularity);
+ cur <= std::min(end, mid + 2 * kGranularity); ++cur) {
+ if (cur == mid ||
+ // Any mid in the last unaligned granule is OK, if bytes after the
+ // storage are not poisoned.
+ (!poison_buffer && RoundDown(end) <= std::min(cur, mid))) {
+ assert(__sanitizer_verify_contiguous_container(beg, cur, end));
+ assert(NULL == __sanitizer_contiguous_container_find_bad_address(
+ beg, cur, end));
+ } else if (cur < mid) {
+ assert(!__sanitizer_verify_contiguous_container(beg, cur, end));
+ assert(cur == __sanitizer_contiguous_container_find_bad_address(
+ beg, cur, end));
+ } else {
+ assert(!__sanitizer_verify_contiguous_container(beg, cur, end));
+ assert(mid == __sanitizer_contiguous_container_find_bad_address(
+ beg, cur, end));
+ }
}
}
More information about the llvm-commits
mailing list