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 %s
4// RUN: env ASAN_OPTIONS=detect_container_overflow=0 %run %t crash
5//
6// Test crash due to __sanitizer_annotate_contiguous_container.
7
8#include <assert.h>
9#include <string.h>
10
11extern "C" {
12void __sanitizer_annotate_contiguous_container(const void *beg, const void *end,
13                                               const void *old_mid,
14                                               const void *new_mid);
15}  // extern "C"
16
17static volatile int one = 1;
18
19int TestCrash() {
20  long t[100];
21  t[60] = 0;
22  __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
23                                            &t[0] + 50);
24  return (int)t[60 * one];  // Touches the poisoned memory.
25}
26
27void BadBounds() {
28  long t[100];
29  __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101,
30                                            &t[0] + 50);
31}
32
33int main(int argc, char **argv) {
34  assert(argc == 2);
35  if (!strcmp(argv[1], "crash"))
36    return TestCrash();
37  else if (!strcmp(argv[1], "bad-bounds"))
38    BadBounds();
39}
40// CHECK-CRASH: AddressSanitizer: container-overflow
41// CHECK-BAD: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
42