diff options
| author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-05-21 09:02:13 +0000 |
|---|---|---|
| committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-05-21 09:02:13 +0000 |
| commit | 208aae8ee0b581683bf25a602585bffc0c3968cc (patch) | |
| tree | f2f825eb96ef174d2a0a362b7c4070fa6241488c /compiler-rt/test/msan/chained_origin_limits.cc | |
| parent | e88161626f2ab30634051931962341058e2c781b (diff) | |
| download | bcm5719-llvm-208aae8ee0b581683bf25a602585bffc0c3968cc.tar.gz bcm5719-llvm-208aae8ee0b581683bf25a602585bffc0c3968cc.zip | |
[msan] Chained origins re-design.
Generalize StackDepot and create a new specialized instance of it to
efficiently (i.e. without duplicating stack trace data) store the
origin history tree.
This reduces memory usage for chained origins roughly by an order of
magnitude.
Most importantly, this new design allows us to put two limits on
stored history data (exposed in MSAN_OPTIONS) that help avoid
exponential growth in used memory on certain workloads.
See comments in lib/msan/msan_origin.h for more details.
llvm-svn: 209284
Diffstat (limited to 'compiler-rt/test/msan/chained_origin_limits.cc')
| -rw-r--r-- | compiler-rt/test/msan/chained_origin_limits.cc | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/compiler-rt/test/msan/chained_origin_limits.cc b/compiler-rt/test/msan/chained_origin_limits.cc new file mode 100644 index 00000000000..c6f8b626c59 --- /dev/null +++ b/compiler-rt/test/msan/chained_origin_limits.cc @@ -0,0 +1,101 @@ +// This test program creates a very large number of unique histories. + +// 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 +// 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> +#include <unistd.h> + +static char *buf, *cur, *end; +void init() { + buf = new char[1000]; + cur = buf; + end = buf + 1000; +} + +void line_flush() { + char *p; + for (p = cur - 1; p >= buf; --p) + if (*p == '\n') + break; + if (p >= buf) { + size_t write_sz = p - buf + 1; + // write(2, buf, write_sz); + memmove(buf, p + 1, end - p - 1); + cur -= write_sz; + } +} + +void buffered_write(const char *p, size_t sz) { + while (sz > 0) { + size_t copy_sz = end - cur; + if (sz < copy_sz) copy_sz = sz; + memcpy(cur, p, copy_sz); + cur += copy_sz; + sz -= copy_sz; + line_flush(); + } +} + +void fn1() { + buffered_write("a\n", 2); +} + +void fn2() { + buffered_write("a\n", 2); +} + +void fn3() { + buffered_write("a\n", 2); +} + +int main(void) { + init(); + for (int i = 0; i < 2000; ++i) { + fn1(); + fn2(); + fn3(); + } + return buf[50]; +} + +// CHECK7: WARNING: MemorySanitizer: use-of-uninitialized-value +// 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 stored to memory at +// 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 stored to memory at +// 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 stored to memory at +// CHECK7-NOT: Uninitialized value was stored to memory at +// CHECK7: Uninitialized value was created by a heap allocation + +// 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 + +// CHECK-PER-STACK: WARNING: MemorySanitizer: use-of-uninitialized-value +// CHECK-PER-STACK: Uninitialized value was stored to memory at +// CHECK-PER-STACK: in fn3 +// CHECK-PER-STACK: Uninitialized value was stored to memory at +// 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 |

