summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/asan/TestCases/Linux/aligned_alloc-alignment.cc25
-rw-r--r--compiler-rt/test/asan/TestCases/Posix/posix_memalign-alignment.cc22
-rw-r--r--compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc25
-rw-r--r--compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc22
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Linux/aligned_alloc-alignment.cc32
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc31
6 files changed, 63 insertions, 94 deletions
diff --git a/compiler-rt/test/asan/TestCases/Linux/aligned_alloc-alignment.cc b/compiler-rt/test/asan/TestCases/Linux/aligned_alloc-alignment.cc
deleted file mode 100644
index 10ce95fcd45..00000000000
--- a/compiler-rt/test/asan/TestCases/Linux/aligned_alloc-alignment.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
-
-// UNSUPPORTED: android
-
-// REQUIRES: stable-runtime
-
-#include <stdio.h>
-#include <stdlib.h>
-
-extern void *aligned_alloc(size_t alignment, size_t size);
-
-int main() {
- void *p = aligned_alloc(17, 100);
- // CHECK: ERROR: AddressSanitizer: invalid allocation alignment: 17
- // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
- // CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cc:}}[[@LINE-3]]
- // CHECK: SUMMARY: AddressSanitizer: invalid-allocation-alignment
-
- printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
- // CHECK-NULL: pointer after failed aligned_alloc: 0
-
- return 0;
-}
diff --git a/compiler-rt/test/asan/TestCases/Posix/posix_memalign-alignment.cc b/compiler-rt/test/asan/TestCases/Posix/posix_memalign-alignment.cc
deleted file mode 100644
index 1391292d23c..00000000000
--- a/compiler-rt/test/asan/TestCases/Posix/posix_memalign-alignment.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
-
-// REQUIRES: stable-runtime
-
-#include <stdio.h>
-#include <stdlib.h>
-
-int main() {
- void *p = reinterpret_cast<void*>(42);
- int res = posix_memalign(&p, 17, 100);
- // CHECK: ERROR: AddressSanitizer: invalid alignment requested in posix_memalign: 17
- // CHECK: {{#0 0x.* in .*posix_memalign}}
- // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cc:}}[[@LINE-3]]
- // CHECK: SUMMARY: AddressSanitizer: invalid-posix-memalign-alignment
-
- printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
- // CHECK-NULL: pointer after failed posix_memalign: 42
-
- return 0;
-}
diff --git a/compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc b/compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc
deleted file mode 100644
index 370691d5810..00000000000
--- a/compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clangxx_lsan -O0 %s -o %t
-// RUN: %env_lsan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
-// RUN: %env_lsan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
-
-// UNSUPPORTED: android
-
-// REQUIRES: stable-runtime
-
-#include <stdio.h>
-#include <stdlib.h>
-
-extern void *aligned_alloc(size_t alignment, size_t size);
-
-int main() {
- void *p = aligned_alloc(17, 100);
- // CHECK: {{ERROR: .*Sanitizer: invalid allocation alignment: 17}}
- // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
- // CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cc:}}[[@LINE-3]]
- // CHECK: {{SUMMARY: .*Sanitizer: invalid-allocation-alignment}}
-
- printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
- // CHECK-NULL: pointer after failed aligned_alloc: 0
-
- return 0;
-}
diff --git a/compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc b/compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc
deleted file mode 100644
index 1b9b14ebe26..00000000000
--- a/compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-// RUN: %clangxx_lsan -O0 %s -o %t
-// RUN: %env_lsan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
-// RUN: %env_lsan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
-
-// REQUIRES: stable-runtime
-
-#include <stdio.h>
-#include <stdlib.h>
-
-int main() {
- void *p = reinterpret_cast<void*>(42);
- int res = posix_memalign(&p, 17, 100);
- // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in posix_memalign: 17}}
- // CHECK: {{#0 0x.* in .*posix_memalign}}
- // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cc:}}[[@LINE-3]]
- // CHECK: {{SUMMARY: .*Sanitizer: invalid-posix-memalign-alignment}}
-
- printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
- // CHECK-NULL: pointer after failed posix_memalign: 42
-
- return 0;
-}
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;
+}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc
new file mode 100644
index 00000000000..457855d4442
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc
@@ -0,0 +1,31 @@
+// 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
+
+// REQUIRES: stable-runtime
+
+// UNSUPPORTED: msan, tsan, ubsan
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv) {
+ assert(argc == 2);
+ const int alignment = atoi(argv[1]);
+
+ void *p = reinterpret_cast<void*>(42);
+
+ int res = posix_memalign(&p, alignment, 100);
+ // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in posix_memalign}}
+ // CHECK: {{#0 0x.* in .*posix_memalign}}
+ // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cc:}}[[@LINE-3]]
+ // CHECK: {{SUMMARY: .*Sanitizer: invalid-posix-memalign-alignment}}
+
+ printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
+ // CHECK-NULL: pointer after failed posix_memalign: 42
+
+ return 0;
+}
OpenPOWER on IntegriCloud