blob: 5b999c04930ca31136b96061262d80dbef065886 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clangxx_asan -O %s -o %t
2// RUN: not %run %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
Stephen Hines86277eb2015-03-23 12:06:32 -07003// RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s
4// RUN: not %run %t bad-alignment 2>&1 | FileCheck --check-prefix=CHECK-BAD-ALIGNMENT %s
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08005// RUN: %env_asan_opts=detect_container_overflow=0 %run %t crash
Stephen Hines2d1fdb22014-05-28 23:58:16 -07006//
7// Test crash due to __sanitizer_annotate_contiguous_container.
8
9#include <assert.h>
10#include <string.h>
11
12extern "C" {
13void __sanitizer_annotate_contiguous_container(const void *beg, const void *end,
14 const void *old_mid,
15 const void *new_mid);
16} // extern "C"
17
18static volatile int one = 1;
19
20int TestCrash() {
21 long t[100];
22 t[60] = 0;
23 __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
24 &t[0] + 50);
Stephen Hines86277eb2015-03-23 12:06:32 -070025// CHECK-CRASH: AddressSanitizer: container-overflow
Stephen Hines2d1fdb22014-05-28 23:58:16 -070026 return (int)t[60 * one]; // Touches the poisoned memory.
27}
28
29void BadBounds() {
30 long t[100];
Stephen Hines86277eb2015-03-23 12:06:32 -070031// CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
Stephen Hines2d1fdb22014-05-28 23:58:16 -070032 __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101,
33 &t[0] + 50);
34}
35
Stephen Hines86277eb2015-03-23 12:06:32 -070036void BadAlignment() {
37 int t[100];
38// CHECK-BAD-ALIGNMENT: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
39// CHECK-BAD-ALIGNMENT: ERROR: beg is not aligned by 8
40 __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[1] + 10,
41 &t[0] + 50);
42}
43
Stephen Hines2d1fdb22014-05-28 23:58:16 -070044int main(int argc, char **argv) {
45 assert(argc == 2);
46 if (!strcmp(argv[1], "crash"))
47 return TestCrash();
48 else if (!strcmp(argv[1], "bad-bounds"))
49 BadBounds();
Stephen Hines86277eb2015-03-23 12:06:32 -070050 else if (!strcmp(argv[1], "bad-alignment"))
51 BadAlignment();
Stephen Hines2d1fdb22014-05-28 23:58:16 -070052}