aboutsummaryrefslogtreecommitdiff
path: root/test/msan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-02-10 07:45:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-02-10 07:45:43 +0000
commit476c4db3dc56bee43df384704c75ccc71cfa7a1d (patch)
tree5d0dcec3cc12fc53532fc84029892b98711a2596 /test/msan
parentca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (diff)
downloadsrc-476c4db3dc56bee43df384704c75ccc71cfa7a1d.tar.gz
src-476c4db3dc56bee43df384704c75ccc71cfa7a1d.zip
Import compiler-rt trunk r228651.vendor/compiler-rt/compiler-rt-r228651
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=278497 svn path=/vendor/compiler-rt/compiler-rt-r228651/; revision=278498; tag=vendor/compiler-rt/compiler-rt-r228651
Diffstat (limited to 'test/msan')
-rw-r--r--test/msan/msan_print_shadow.cc6
-rw-r--r--test/msan/origin-store-long.cc21
-rw-r--r--test/msan/realloc-large-origin.cc30
-rw-r--r--test/msan/realloc-origin.cc21
-rw-r--r--test/msan/select_float_origin.cc2
-rw-r--r--test/msan/use-after-free.cc2
6 files changed, 77 insertions, 5 deletions
diff --git a/test/msan/msan_print_shadow.cc b/test/msan/msan_print_shadow.cc
index 0cc1d660be1b..f4894596a0e2 100644
--- a/test/msan/msan_print_shadow.cc
+++ b/test/msan/msan_print_shadow.cc
@@ -99,7 +99,7 @@ int main(void) {
// CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:14
// CHECK-ORIGINS: Origin B (origin_id {{.*}}):
-// CHECK-ORIGINS: Uninitialized value was created by a heap allocation
+// CHECK-ORIGINS: Memory was marked as uninitialized
// CHECK-ORIGINS: #0 {{.*}} in __msan_allocated_memory
// CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:18
@@ -110,13 +110,13 @@ int main(void) {
// CHECK-ORIGINS: #0 {{.*}} in main{{.*}}msan_print_shadow.cc:12
// CHECK-ORIGINS: Origin D (origin_id {{.*}}):
-// CHECK-ORIGINS: Uninitialized value was created by a heap allocation
+// CHECK-ORIGINS: Memory was marked as uninitialized
// CHECK-ORIGINS: #0 {{.*}} in __msan_allocated_memory
// CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:20
// ...
// CHECK-ORIGINS: Origin Z (origin_id {{.*}}):
-// CHECK-ORIGINS: Uninitialized value was created by a heap allocation
+// CHECK-ORIGINS: Memory was marked as uninitialized
// CHECK-ORIGINS: #0 {{.*}} in __msan_allocated_memory
// CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:42
diff --git a/test/msan/origin-store-long.cc b/test/msan/origin-store-long.cc
new file mode 100644
index 000000000000..a7c2b7a7d578
--- /dev/null
+++ b/test/msan/origin-store-long.cc
@@ -0,0 +1,21 @@
+// Check that 8-byte store updates origin for the full store range.
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O2 %s -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s < %t.out
+
+#include <sanitizer/msan_interface.h>
+
+int main() {
+ uint64_t *volatile p = new uint64_t;
+ uint64_t *volatile q = new uint64_t;
+ *p = *q;
+ char *z = (char *)p;
+ return z[6];
+// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+// CHECK: in main {{.*}}origin-store-long.cc:[[@LINE-2]]
+
+// CHECK: Uninitialized value was created by a heap allocation
+// CHECK: in main {{.*}}origin-store-long.cc:[[@LINE-8]]
+}
+
diff --git a/test/msan/realloc-large-origin.cc b/test/msan/realloc-large-origin.cc
new file mode 100644
index 000000000000..de39394cbb79
--- /dev/null
+++ b/test/msan/realloc-large-origin.cc
@@ -0,0 +1,30 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -O0 %s -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -O2 %s -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+// This is a regression test: there used to be broken "stored to memory at"
+// stacks with
+// in __msan_memcpy
+// in __msan::MsanReallocate
+// and nothing below that.
+
+#include <stdlib.h>
+int main(int argc, char **argv) {
+ char *p = (char *)malloc(100);
+ p = (char *)realloc(p, 10000);
+ char x = p[50];
+ free(p);
+ return x;
+
+// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+// CHECK: {{#0 0x.* in main .*realloc-large-origin.cc:}}[[@LINE-3]]
+
+// CHECK: Uninitialized value was stored to memory at
+// CHECK: {{#0 0x.* in .*realloc}}
+// CHECK: {{#1 0x.* in main .*realloc-large-origin.cc:}}[[@LINE-10]]
+
+// CHECK: Uninitialized value was created by a heap allocation
+// CHECK: {{#0 0x.* in .*malloc}}
+// CHECK: {{#1 0x.* in main .*realloc-large-origin.cc:}}[[@LINE-15]]
+}
diff --git a/test/msan/realloc-origin.cc b/test/msan/realloc-origin.cc
new file mode 100644
index 000000000000..6707cc9049a4
--- /dev/null
+++ b/test/msan/realloc-origin.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O2 %s -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+// This test relies on realloc from 100 to 101 being done in-place.
+
+#include <stdlib.h>
+int main(int argc, char **argv) {
+ char *p = (char *)malloc(100);
+ p = (char *)realloc(p, 101);
+ char x = p[100];
+ free(p);
+ return x;
+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: {{#0 0x.* in main .*realloc-origin.cc:}}[[@LINE-2]]
+
+ // CHECK: Uninitialized value was created by a heap allocation
+ // CHECK: {{#0 0x.* in .*realloc}}
+ // CHECK: {{#1 0x.* in main .*realloc-origin.cc:}}[[@LINE-9]]
+}
diff --git a/test/msan/select_float_origin.cc b/test/msan/select_float_origin.cc
index ca8f3a83b0ed..75731dc457fb 100644
--- a/test/msan/select_float_origin.cc
+++ b/test/msan/select_float_origin.cc
@@ -17,7 +17,7 @@ int main() {
__msan_allocated_memory(&y, sizeof(y));
float z = b ? x : y;
if (z > 0) printf(".\n");
- // CHECK: Uninitialized value was created by a heap allocation
+ // CHECK: Memory was marked as uninitialized
// CHECK: {{#0 0x.* in .*__msan_allocated_memory}}
// CHECK: {{#1 0x.* in main .*select_float_origin.cc:}}[[@LINE-6]]
return 0;
diff --git a/test/msan/use-after-free.cc b/test/msan/use-after-free.cc
index 5b408c536495..869bad98e455 100644
--- a/test/msan/use-after-free.cc
+++ b/test/msan/use-after-free.cc
@@ -27,7 +27,7 @@ int main(int argc, char **argv) {
// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
// CHECK: {{#0 0x.* in main .*use-after-free.cc:}}[[@LINE-3]]
- // CHECK-ORIGINS: Uninitialized value was created by a heap allocation
+ // CHECK-ORIGINS: Uninitialized value was created by a heap deallocation
// CHECK-ORIGINS: {{#0 0x.* in .*free}}
// CHECK-ORIGINS: {{#1 0x.* in main .*use-after-free.cc:}}[[@LINE-9]]
return 0;