diff options
author | Alex Shlyapnikov <alekseys@google.com> | 2018-02-01 19:52:56 +0000 |
---|---|---|
committer | Alex Shlyapnikov <alekseys@google.com> | 2018-02-01 19:52:56 +0000 |
commit | 3c80f4d9414bd21d5012486dbfcf1fc8f0af951b (patch) | |
tree | 45bccc43c85890ea72a356aa72760a7fe6a50d12 /compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cc | |
parent | 06a715333ad77df68da1562b5b8368eb219fbfd9 (diff) | |
download | bcm5719-llvm-3c80f4d9414bd21d5012486dbfcf1fc8f0af951b.tar.gz bcm5719-llvm-3c80f4d9414bd21d5012486dbfcf1fc8f0af951b.zip |
Make detect_invalid_pointer_pairs option to be tristate.
Summary:
With the change, one can choose not to report comparison (or subtraction)
of a pointer with nullptr pointer.
Reviewers: kcc, jakubjelinek, alekseyshl
Reviewed By: alekseyshl
Subscribers: kubamracek
Differential Revision: https://reviews.llvm.org/D41479
llvm-svn: 323995
Diffstat (limited to 'compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cc')
-rw-r--r-- | compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cc b/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cc new file mode 100644 index 00000000000..dfc56616a4d --- /dev/null +++ b/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cc @@ -0,0 +1,42 @@ +// RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair + +// RUN: %env_asan_opts=detect_invalid_pointer_pairs=1 %run %t + +#include <assert.h> +#include <stdlib.h> + +int foo(char *p, char *q) { + return p <= q; +} + +char global[8192] = {}; +char small_global[7] = {}; + +int main() { + // Heap allocated memory. + char *p = (char *)malloc(42); + int r = foo(p, nullptr); + free(p); + + p = (char *)malloc(1024); + foo(nullptr, p); + free(p); + + p = (char *)malloc(4096); + foo(p, nullptr); + free(p); + + // Global variable. + foo(&global[0], nullptr); + foo(&global[1000], nullptr); + + p = &small_global[0]; + foo(p, nullptr); + + // Stack variable. + char stack[10000]; + foo(&stack[0], nullptr); + foo(nullptr, &stack[9000]); + + return 0; +} |