[compiler-rt] r212036 - [msan] Limit stack origin chain length.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Mon Jun 30 04:22:42 PDT 2014
Author: eugenis
Date: Mon Jun 30 06:22:42 2014
New Revision: 212036
URL: http://llvm.org/viewvc/llvm-project?rev=212036&view=rev
Log:
[msan] Limit stack origin chain length.
Stack origins were created with unlimited length by mistake.
Modified:
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/test/msan/chained_origin_limits.cc
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=212036&r1=212035&r2=212036&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Mon Jun 30 06:22:42 2014
@@ -585,7 +585,7 @@ void __msan_set_alloca_origin4(void *a,
}
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) {
Modified: compiler-rt/trunk/test/msan/chained_origin_limits.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/chained_origin_limits.cc?rev=212036&r1=212035&r2=212036&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/chained_origin_limits.cc (original)
+++ compiler-rt/trunk/test/msan/chained_origin_limits.cc Mon Jun 30 06:22:42 2014
@@ -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
More information about the llvm-commits
mailing list