Move ASan lit-tests under test/asan
[blocksruntime.git] / test / asan / TestCases / contiguous_container_crash.cc
blob6be9ad5f6c01924b5a87292cb535311e73ccc069
1 // RUN: %clangxx_asan -O %s -o %t
2 // RUN: not %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
3 // RUN: not %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD %s
4 // Test crash due to __sanitizer_annotate_contiguous_container.
6 #include <assert.h>
7 #include <string.h>
9 extern "C" {
10 void __sanitizer_annotate_contiguous_container(const void *beg, const void *end,
11 const void *old_mid,
12 const void *new_mid);
13 } // extern "C"
15 static volatile int one = 1;
17 int TestCrash() {
18 long t[100];
19 __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
20 &t[0] + 50);
21 return (int)t[60 * one]; // Touches the poisoned memory.
24 void BadBounds() {
25 long t[100];
26 __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101,
27 &t[0] + 50);
30 int main(int argc, char **argv) {
31 assert(argc == 2);
32 if (!strcmp(argv[1], "crash"))
33 return TestCrash();
34 else if (!strcmp(argv[1], "bad-bounds"))
35 BadBounds();
37 // CHECK-CRASH: AddressSanitizer: container-overflow
38 // CHECK-BAD: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container