aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/msan/Linux/aligned_alloc-alignment.cc26
-rw-r--r--test/msan/allocator_returns_null.cc18
-rw-r--r--test/msan/posix_memalign-alignment.cc22
-rw-r--r--test/msan/pvalloc.cc6
4 files changed, 62 insertions, 10 deletions
diff --git a/test/msan/Linux/aligned_alloc-alignment.cc b/test/msan/Linux/aligned_alloc-alignment.cc
new file mode 100644
index 000000000..86ec7c9d8
--- /dev/null
+++ b/test/msan/Linux/aligned_alloc-alignment.cc
@@ -0,0 +1,26 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t
+// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
+// RUN: MSAN_OPTIONS=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: MemorySanitizer: invalid alignment requested in aligned_alloc: 17
+ // Check just the top frame since mips is forced to use store_context_size==1
+ // and also handle a case when aligned_alloc is aliased by memalign.
+ // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
+ // CHECK: SUMMARY: MemorySanitizer: 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/test/msan/allocator_returns_null.cc b/test/msan/allocator_returns_null.cc
index 583b5b4f7..7e45a1be0 100644
--- a/test/msan/allocator_returns_null.cc
+++ b/test/msan/allocator_returns_null.cc
@@ -30,7 +30,7 @@
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t new 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-nCRASH
// RUN: MSAN_OPTIONS=allocator_may_return_null=1 not %run %t new 2>&1 \
-// RUN: | FileCheck %s --check-prefix=CHECK-nCRASH
+// RUN: | FileCheck %s --check-prefix=CHECK-nCRASH-OOM
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t new-nothrow 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-nnCRASH
// RUN: MSAN_OPTIONS=allocator_may_return_null=1 %run %t new-nothrow 2>&1 \
@@ -98,19 +98,21 @@ int main(int argc, char **argv) {
}
// CHECK-mCRASH: malloc:
-// CHECK-mCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-mCRASH: SUMMARY: MemorySanitizer: allocation-size-too-big
// CHECK-cCRASH: calloc:
-// CHECK-cCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-cCRASH: SUMMARY: MemorySanitizer: allocation-size-too-big
// CHECK-coCRASH: calloc-overflow:
-// CHECK-coCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-coCRASH: SUMMARY: MemorySanitizer: calloc-overflow
// CHECK-rCRASH: realloc:
-// CHECK-rCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-rCRASH: SUMMARY: MemorySanitizer: allocation-size-too-big
// CHECK-mrCRASH: realloc-after-malloc:
-// CHECK-mrCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-mrCRASH: SUMMARY: MemorySanitizer: allocation-size-too-big
// CHECK-nCRASH: new:
-// CHECK-nCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-nCRASH: SUMMARY: MemorySanitizer: allocation-size-too-big
+// CHECK-nCRASH-OOM: new:
+// CHECK-nCRASH-OOM: SUMMARY: MemorySanitizer: out-of-memory
// CHECK-nnCRASH: new-nothrow:
-// CHECK-nnCRASH: MemorySanitizer's allocator is terminating the process
+// CHECK-nnCRASH: SUMMARY: MemorySanitizer: allocation-size-too-big
// CHECK-mNULL: malloc:
// CHECK-mNULL: errno: 12
diff --git a/test/msan/posix_memalign-alignment.cc b/test/msan/posix_memalign-alignment.cc
new file mode 100644
index 000000000..0bb8e324d
--- /dev/null
+++ b/test/msan/posix_memalign-alignment.cc
@@ -0,0 +1,22 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t
+// RUN: MSAN_OPTIONS=$MSAN_OPTIONS:allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
+// RUN: MSAN_OPTIONS=$MSAN_OPTIONS: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: MemorySanitizer: invalid alignment requested in posix_memalign: 17
+ // Check just the top frame since mips is forced to use store_context_size==1
+ // CHECK: {{#0 0x.* in .*posix_memalign}}
+ // CHECK: SUMMARY: MemorySanitizer: 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/test/msan/pvalloc.cc b/test/msan/pvalloc.cc
index 649719a88..a85f4cad7 100644
--- a/test/msan/pvalloc.cc
+++ b/test/msan/pvalloc.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -O0 %s -o %t
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t m1 2>&1 | FileCheck %s
// RUN: MSAN_OPTIONS=allocator_may_return_null=1 %run %t m1 2>&1
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t psm1 2>&1 | FileCheck %s
@@ -41,4 +41,6 @@ int main(int argc, char *argv[]) {
return 0;
}
-// CHECK: MemorySanitizer's allocator is terminating the process
+// CHECK: {{ERROR: MemorySanitizer: pvalloc parameters overflow: size .* rounded up to system page size .* cannot be represented in type size_t}}
+// CHECK: {{#0 0x.* in .*pvalloc}}
+// CHECK: SUMMARY: MemorySanitizer: pvalloc-overflow