summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/memset_test.cc
blob: ea7702566fcb6ede4155aa628b1c32928034613e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Test that large memset/memcpy/memmove check the entire range.

// RUN: %clangxx_asan -O0 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O1 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O2 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET
// RUN: %clangxx_asan -O3 -DTEST_MEMSET %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET

// RUN: %clangxx_asan -O0 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O1 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O2 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY
// RUN: %clangxx_asan -O3 -DTEST_MEMCPY %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY

// RUN: %clangxx_asan -O0 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O1 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O2 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE
// RUN: %clangxx_asan -O3 -DTEST_MEMMOVE %s -o %t && not %t 2>&1 | \
// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include <sanitizer/asan_interface.h>

int main(int argc, char **argv) {
  char * volatile p = (char *)malloc(3000);
  __asan_poison_memory_region(p + 512, 16);
#if defined(TEST_MEMSET)
  memset(p, 0, 3000);
  assert(p[1] == 0);
  // CHECK-MEMSET: AddressSanitizer: use-after-poison on address
  // CHECK-MEMSET: in {{.*}}memset
#else
  char * volatile q = (char *)malloc(3000);
#if defined(TEST_MEMCPY)
  memcpy(q, p, 3000);
  // CHECK-MEMCPY: AddressSanitizer: use-after-poison on address
  // On Mac, memmove and memcpy are the same. Accept either one.
  // CHECK-MEMCPY: in {{.*(memmove|memcpy)}}
#elif defined(TEST_MEMMOVE)
  memmove(q, p, 3000);
  // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address
  // CHECK-MEMMOVE: in {{.*(memmove|memcpy)}}
#endif
  assert(q[1] == 0);
  free(q);
#endif
  free(p);
  return 0;
}