summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/memset_test.cc
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-03-26 12:14:34 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-03-26 12:14:34 +0000
commite4922865c2a0ccb4380adcf27f50a6443b9c168e (patch)
treebc9ac666ffdba581c0acc3813e6a410e50603e05 /test/asan/TestCases/memset_test.cc
parent7910f467b07ae5d30e29ecea523729425e80060e (diff)
[sanitizer] Intercept __aeabi_mem(set|cpy|move).
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/memset_test.cc')
-rw-r--r--test/asan/TestCases/memset_test.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/asan/TestCases/memset_test.cc b/test/asan/TestCases/memset_test.cc
new file mode 100644
index 000000000..37898e143
--- /dev/null
+++ b/test/asan/TestCases/memset_test.cc
@@ -0,0 +1,61 @@
+// 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
+ // CHECK-MEMCPY: in {{.*}}memcpy
+#elif defined(TEST_MEMMOVE)
+ memmove(q, p, 3000);
+ // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address
+ // CHECK-MEMMOVE: in {{.*}}memmove
+#endif
+ assert(q[1] == 0);
+ free(q);
+#endif
+ free(p);
+ return 0;
+}