diff options
author | Vitaly Buka <vitalybuka@google.com> | 2017-04-21 19:39:46 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2017-04-21 19:39:46 +0000 |
commit | c8d70402d14b60b77a8ab84fd1dac4153a0bdeb7 (patch) | |
tree | ee5037377860a00f90533d413aa90105d62db0c4 /test/asan/TestCases | |
parent | 6d68f82042320a09156b04a41bbfc1a10e695d4a (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301027 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases')
-rw-r--r-- | test/asan/TestCases/Posix/strchr.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/asan/TestCases/Posix/strchr.c b/test/asan/TestCases/Posix/strchr.c new file mode 100644 index 000000000..7086e1374 --- /dev/null +++ b/test/asan/TestCases/Posix/strchr.c @@ -0,0 +1,34 @@ +// 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|BUS}} on unknown address + assert(r == p); + + return 0; +} |