1 // Test that large memset/memcpy/memmove check the entire range.
3 // RUN: %clangxx_asan -O0 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
4 // RUN: FileCheck %s --check-prefix=CHECK-MEMSET
5 // RUN: %clangxx_asan -O1 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
6 // RUN: FileCheck %s --check-prefix=CHECK-MEMSET
7 // RUN: %clangxx_asan -O2 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
8 // RUN: FileCheck %s --check-prefix=CHECK-MEMSET
9 // RUN: %clangxx_asan -O3 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \
10 // RUN: FileCheck %s --check-prefix=CHECK-MEMSET
12 // RUN: %clangxx_asan -O0 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
13 // RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
14 // RUN: %clangxx_asan -O1 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
15 // RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
16 // RUN: %clangxx_asan -O2 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
17 // RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
18 // RUN: %clangxx_asan -O3 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \
19 // RUN: FileCheck %s --check-prefix=CHECK-MEMCPY
21 // RUN: %clangxx_asan -O0 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
22 // RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
23 // RUN: %clangxx_asan -O1 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
24 // RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
25 // RUN: %clangxx_asan -O2 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
26 // RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
27 // RUN: %clangxx_asan -O3 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \
28 // RUN: FileCheck %s --check-prefix=CHECK-MEMMOVE
30 // RUN: %clangxx_asan -O2 -DTEST_MEMCPY_SIZE_OVERFLOW %s -o %t && not %run %t 2>&1 | \
31 // RUN: FileCheck %s --check-prefix=CHECK-MEMCPY_SIZE_OVERFLOW
38 #include <sanitizer/asan_interface.h>
40 typedef void *(*memcpy_t
)(void *, const void *, size_t);
42 int main(int argc
, char **argv
) {
43 char * volatile p
= (char *)malloc(3000);
44 __asan_poison_memory_region(p
+ 512, 32);
45 #if defined(TEST_MEMSET)
48 // CHECK-MEMSET: AddressSanitizer: use-after-poison on address
49 // CHECK-MEMSET: in {{.*}}memset
51 char * volatile q
= (char *)malloc(3000);
52 #if defined(TEST_MEMCPY)
54 // CHECK-MEMCPY: AddressSanitizer: use-after-poison on address
55 // On Mac, memmove and memcpy are the same. Accept either one.
56 // CHECK-MEMCPY: in {{.*(memmove|memcpy)}}
57 #elif defined(TEST_MEMMOVE)
59 // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address
60 // CHECK-MEMMOVE: in {{.*(memmove|memcpy)}}
61 #elif defined(TEST_MEMCPY_SIZE_OVERFLOW)
62 volatile memcpy_t my_memcpy
= &memcpy
;
63 my_memcpy(p
, q
, -argc
);
64 // CHECK-MEMCPY_SIZE_OVERFLOW: AddressSanitizer: negative-size-param: (size=-1)