diff options
author | Alex Shlyapnikov <alekseys@google.com> | 2018-06-08 20:40:35 +0000 |
---|---|---|
committer | Alex Shlyapnikov <alekseys@google.com> | 2018-06-08 20:40:35 +0000 |
commit | dcf0097962e4506aec59fbbd01c874527d2e061d (patch) | |
tree | 1a41b71908299f93693d176a5cb9b94ea7a9de77 /compiler-rt/test/sanitizer_common/TestCases/Linux | |
parent | 9e5eafbaa8ab0d49ccfd197a91b386e9aba28972 (diff) | |
download | bcm5719-llvm-dcf0097962e4506aec59fbbd01c874527d2e061d.tar.gz bcm5719-llvm-dcf0097962e4506aec59fbbd01c874527d2e061d.zip |
[Sanitizers] Check alignment != 0 for aligned_alloc and posix_memalign
Summary:
Move the corresponding tests to the common folder (as all of the
sanitizer allocators will support this feature soon) and add the checks
specific to aligned_alloc to ASan and LSan allocators.
Reviewers: vitalybuka
Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D47924
llvm-svn: 334316
Diffstat (limited to 'compiler-rt/test/sanitizer_common/TestCases/Linux')
-rw-r--r-- | compiler-rt/test/sanitizer_common/TestCases/Linux/aligned_alloc-alignment.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/aligned_alloc-alignment.cc b/compiler-rt/test/sanitizer_common/TestCases/Linux/aligned_alloc-alignment.cc new file mode 100644 index 00000000000..67b66f1e1a8 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/aligned_alloc-alignment.cc @@ -0,0 +1,32 @@ +// RUN: %clangxx -O0 %s -o %t +// RUN: %tool_options=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s +// RUN: %tool_options=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s +// RUN: %tool_options=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL +// RUN: %tool_options=allocator_may_return_null=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL + +// UNSUPPORTED: android, msan, tsan, ubsan + +// REQUIRES: stable-runtime + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +extern void *aligned_alloc(size_t alignment, size_t size); + +int main(int argc, char **argv) { + assert(argc == 2); + const int alignment = atoi(argv[1]); + + void *p = aligned_alloc(alignment, 100); + // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in aligned_alloc}} + // Handle a case when aligned_alloc is aliased by memalign. + // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}} + // CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cc:}}[[@LINE-4]] + // CHECK: {{SUMMARY: .*Sanitizer: invalid-aligned-alloc-alignment}} + + printf("pointer after failed aligned_alloc: %zd\n", (size_t)p); + // CHECK-NULL: pointer after failed aligned_alloc: 0 + + return 0; +} |