1 // RUN: %clangxx_asan -O %s -o %t
2 // RUN: not %run %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
3 // RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s
4 // 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"
5 // RUN: not %run %t odd-alignment 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
6 // RUN: not %run %t odd-alignment-end 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
7 // RUN: %env_asan_opts=detect_container_overflow=0 %run %t crash
9 // Test crash due to __sanitizer_annotate_contiguous_container.
15 void __sanitizer_annotate_contiguous_container(const void *beg
, const void *end
,
20 static volatile int one
= 1;
25 __sanitizer_annotate_contiguous_container(&t
[0], &t
[0] + 100, &t
[0] + 100,
27 // CHECK-CRASH: AddressSanitizer: container-overflow
28 // CHECK-CRASH: if you don't care about these errors you may set ASAN_OPTIONS=detect_container_overflow=0
29 return (int)t
[60 * one
]; // Touches the poisoned memory.
34 // CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
35 __sanitizer_annotate_contiguous_container(&t
[0], &t
[0] + 100, &t
[0] + 101,
39 void UnalignedBadBounds() {
41 // CHECK-UNALIGNED-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
42 __sanitizer_annotate_contiguous_container(&t
[1], &t
[0] + 100, &t
[0] + 101,
49 __sanitizer_annotate_contiguous_container(&t
[1], &t
[0] + 100, &t
[0] + 100,
51 return (int)t
[60 * one
]; // Touches the poisoned memory.
54 int OddAlignmentEnd() {
57 __sanitizer_annotate_contiguous_container(&t
[0], &t
[0] + 98, &t
[0] + 98,
59 return (int)t
[60 * one
]; // Touches the poisoned memory.
62 int main(int argc
, char **argv
) {
64 if (!strcmp(argv
[1], "crash"))
66 else if (!strcmp(argv
[1], "bad-bounds"))
68 else if (!strcmp(argv
[1], "unaligned-bad-bounds"))
70 else if (!strcmp(argv
[1], "odd-alignment"))
71 return OddAlignment();
72 else if (!strcmp(argv
[1], "odd-alignment-end"))
73 return OddAlignmentEnd();