summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-06-30 11:22:42 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-06-30 11:22:42 +0000
commitf8da2588dba1ecc7eeb97124af583fd94d9bc2fe (patch)
treed3cbe124b7fe7c0ece4f5c55a359262d2af7df2e
parent949cd24a6273f2b2c739d070fa89351f6a54cc22 (diff)
downloadcompiler-rt-f8da2588dba1ecc7eeb97124af583fd94d9bc2fe.tar.gz
[msan] Limit stack origin chain length.
Stack origins were created with unlimited length by mistake. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212036 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/msan/msan.cc2
-rw-r--r--test/msan/chained_origin_limits.cc38
2 files changed, 36 insertions, 4 deletions
diff --git a/lib/msan/msan.cc b/lib/msan/msan.cc
index 6d681b19e..fd7fdbba5 100644
--- a/lib/msan/msan.cc
+++ b/lib/msan/msan.cc
@@ -585,7 +585,7 @@ void __msan_set_alloca_origin4(void *a, uptr size, const char *descr, uptr pc) {
}
if (print)
Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
- __msan_set_origin(a, size, id);
+ __msan_set_origin(a, size, Origin(id, 1).raw_id());
}
u32 __msan_chain_origin(u32 id) {
diff --git a/test/msan/chained_origin_limits.cc b/test/msan/chained_origin_limits.cc
index 08854f25f..a8621f3ae 100644
--- a/test/msan/chained_origin_limits.cc
+++ b/test/msan/chained_origin_limits.cc
@@ -1,5 +1,6 @@
// This test program creates a very large number of unique histories.
+// Heap origin.
// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
@@ -11,7 +12,20 @@
// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+// Stack origin.
+// RUN: %clangxx_msan -DSTACK -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
+// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+
+
+// Heap origin, with calls.
// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
@@ -23,6 +37,19 @@
// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+
+// Stack origin, with calls.
+// RUN: %clangxx_msan -DSTACK -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
+
+// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -31,6 +58,11 @@
static char *buf, *cur, *end;
void init() {
buf = new char[1000];
+#ifdef STACK
+ char stackbuf[1000];
+ char *volatile p = stackbuf;
+ memcpy(buf, p, 1000);
+#endif
cur = buf;
end = buf + 1000;
}
@@ -95,13 +127,13 @@ int main(void) {
// CHECK7-NOT: Uninitialized value was stored to memory at
// CHECK7: Uninitialized value was stored to memory at
// CHECK7-NOT: Uninitialized value was stored to memory at
-// CHECK7: Uninitialized value was created by a heap allocation
+// CHECK7: Uninitialized value was created
// CHECK2: WARNING: MemorySanitizer: use-of-uninitialized-value
// CHECK2-NOT: Uninitialized value was stored to memory at
// CHECK2: Uninitialized value was stored to memory at
// CHECK2-NOT: Uninitialized value was stored to memory at
-// CHECK2: Uninitialized value was created by a heap allocation
+// CHECK2: Uninitialized value was created
// CHECK-PER-STACK: WARNING: MemorySanitizer: use-of-uninitialized-value
// CHECK-PER-STACK: Uninitialized value was stored to memory at
@@ -110,4 +142,4 @@ int main(void) {
// CHECK-PER-STACK: in fn2
// CHECK-PER-STACK: Uninitialized value was stored to memory at
// CHECK-PER-STACK: in fn1
-// CHECK-PER-STACK: Uninitialized value was created by a heap allocation
+// CHECK-PER-STACK: Uninitialized value was created