summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/asan/TestCases/Posix/strchr.c
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2017-04-20 20:59:37 +0000
committerVitaly Buka <vitalybuka@google.com>2017-04-20 20:59:37 +0000
commitf50f97c9dd7fa784bf9d894ea3c6e843cd9b2472 (patch)
treee7afa57e44452f7e6930738f9c018e9f97fef760 /compiler-rt/test/asan/TestCases/Posix/strchr.c
parentfb5b3e773af3e05c7582ea35fbc8b20d8678e649 (diff)
downloadbcm5719-llvm-f50f97c9dd7fa784bf9d894ea3c6e843cd9b2472.tar.gz
bcm5719-llvm-f50f97c9dd7fa784bf9d894ea3c6e843cd9b2472.zip
[asan] Optimize strchr for strict_string_checks=false
Summary: strchr interceptor does not need to call strlen if strict_string_checks is not enabled. Unnecessary strlen calls affect python parser performance. Reviewers: eugenis, kcc Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D32264 llvm-svn: 300889
Diffstat (limited to 'compiler-rt/test/asan/TestCases/Posix/strchr.c')
-rw-r--r--compiler-rt/test/asan/TestCases/Posix/strchr.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Posix/strchr.c b/compiler-rt/test/asan/TestCases/Posix/strchr.c
new file mode 100644
index 00000000000..df854d79ec8
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Posix/strchr.c
@@ -0,0 +1,36 @@
+// Test strchr for strict_string_checks=false does not look beyond necessary
+// char.
+// RUN: %clang_asan %s -o %t
+// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ size_t page_size = sysconf(_SC_PAGE_SIZE);
+ size_t size = 2 * page_size;
+ char *s = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ assert(s);
+ assert(((uintptr_t)s & (page_size - 1)) == 0);
+ memset(s, 'o', size);
+ s[size - 1] = 0;
+
+ char *p = s + page_size - 1;
+ *p = 'x';
+
+ if (mprotect(p + 1, 1, PROT_NONE))
+ return 1;
+ char *r = strchr(s, 'x');
+ // CHECK: AddressSanitizer: SEGV on unknown address
+ // CHECK: The signal is caused by a READ memory access
+ // CHECK: strchr.c:[[@LINE-3]]
+ assert(r == p);
+
+ return 0;
+}
OpenPOWER on IntegriCloud