[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / msan / chained_origin_limits.cc
blobc6f8b626c59b19347fe2b9fe3ad2d07f923ca7b8
1 // This test program creates a very large number of unique histories.
3 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
5 // RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
6 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
8 // RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
9 // RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
11 // RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
12 // RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
19 static char *buf, *cur, *end;
20 void init() {
21 buf = new char[1000];
22 cur = buf;
23 end = buf + 1000;
26 void line_flush() {
27 char *p;
28 for (p = cur - 1; p >= buf; --p)
29 if (*p == '\n')
30 break;
31 if (p >= buf) {
32 size_t write_sz = p - buf + 1;
33 // write(2, buf, write_sz);
34 memmove(buf, p + 1, end - p - 1);
35 cur -= write_sz;
39 void buffered_write(const char *p, size_t sz) {
40 while (sz > 0) {
41 size_t copy_sz = end - cur;
42 if (sz < copy_sz) copy_sz = sz;
43 memcpy(cur, p, copy_sz);
44 cur += copy_sz;
45 sz -= copy_sz;
46 line_flush();
50 void fn1() {
51 buffered_write("a\n", 2);
54 void fn2() {
55 buffered_write("a\n", 2);
58 void fn3() {
59 buffered_write("a\n", 2);
62 int main(void) {
63 init();
64 for (int i = 0; i < 2000; ++i) {
65 fn1();
66 fn2();
67 fn3();
69 return buf[50];
72 // CHECK7: WARNING: MemorySanitizer: use-of-uninitialized-value
73 // CHECK7-NOT: Uninitialized value was stored to memory at
74 // CHECK7: Uninitialized value was stored to memory at
75 // CHECK7-NOT: Uninitialized value was stored to memory at
76 // CHECK7: Uninitialized value was stored to memory at
77 // CHECK7-NOT: Uninitialized value was stored to memory at
78 // CHECK7: Uninitialized value was stored to memory at
79 // CHECK7-NOT: Uninitialized value was stored to memory at
80 // CHECK7: Uninitialized value was stored to memory at
81 // CHECK7-NOT: Uninitialized value was stored to memory at
82 // CHECK7: Uninitialized value was stored to memory at
83 // CHECK7-NOT: Uninitialized value was stored to memory at
84 // CHECK7: Uninitialized value was stored to memory at
85 // CHECK7-NOT: Uninitialized value was stored to memory at
86 // CHECK7: Uninitialized value was created by a heap allocation
88 // CHECK2: WARNING: MemorySanitizer: use-of-uninitialized-value
89 // CHECK2-NOT: Uninitialized value was stored to memory at
90 // CHECK2: Uninitialized value was stored to memory at
91 // CHECK2-NOT: Uninitialized value was stored to memory at
92 // CHECK2: Uninitialized value was created by a heap allocation
94 // CHECK-PER-STACK: WARNING: MemorySanitizer: use-of-uninitialized-value
95 // CHECK-PER-STACK: Uninitialized value was stored to memory at
96 // CHECK-PER-STACK: in fn3
97 // CHECK-PER-STACK: Uninitialized value was stored to memory at
98 // CHECK-PER-STACK: in fn2
99 // CHECK-PER-STACK: Uninitialized value was stored to memory at
100 // CHECK-PER-STACK: in fn1
101 // CHECK-PER-STACK: Uninitialized value was created by a heap allocation