brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 0530c84 Raw
72 lines · cpp
1// Test that large memset/memcpy/memmove check the entire range.2 3// RUN: %clangxx_asan -O0 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \4// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET5// RUN: %clangxx_asan -O1 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \6// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET7// RUN: %clangxx_asan -O2 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \8// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET9// RUN: %clangxx_asan -O3 -DTEST_MEMSET %s -o %t && not %run %t 2>&1 | \10// RUN:     FileCheck %s --check-prefix=CHECK-MEMSET11 12// RUN: %clangxx_asan -O0 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \13// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY14// RUN: %clangxx_asan -O1 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \15// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY16// RUN: %clangxx_asan -O2 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \17// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY18// RUN: %clangxx_asan -O3 -DTEST_MEMCPY %s -o %t && not %run %t 2>&1 | \19// RUN:     FileCheck %s --check-prefix=CHECK-MEMCPY20 21// RUN: %clangxx_asan -O0 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \22// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE23// RUN: %clangxx_asan -O1 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \24// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE25// RUN: %clangxx_asan -O2 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \26// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE27// RUN: %clangxx_asan -O3 -DTEST_MEMMOVE %s -o %t && not %run %t 2>&1 | \28// RUN:     FileCheck %s --check-prefix=CHECK-MEMMOVE29 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_OVERFLOW32 33#include <assert.h>34#include <string.h>35#include <stdlib.h>36#include <stdio.h>37 38#include <sanitizer/asan_interface.h>39 40typedef void *(*memcpy_t)(void *, const void *, size_t);41 42int 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)46  memset(p, 0, 3000);47  assert(p[1] == 0);48  // CHECK-MEMSET: AddressSanitizer: use-after-poison on address49  // CHECK-MEMSET: in {{.*}}memset50#else51  char * volatile q = (char *)malloc(3000);52#if defined(TEST_MEMCPY)53  memcpy(q, p, 3000);54  // CHECK-MEMCPY: AddressSanitizer: use-after-poison on address55  // On Mac, memmove and memcpy are the same. Accept either one.56  // CHECK-MEMCPY: in {{.*(memmove|memcpy)}}57#elif defined(TEST_MEMMOVE)58  memmove(q, p, 3000);59  // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address60  // 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)65#endif66  assert(q[1] == 0);67  free(q);68#endif69  free(p);70  return 0;71}72