1 // This test program creates a very large number of unique histories.
4 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t
6 // RUN: env MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
7 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
9 // RUN: env MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
10 // RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
12 // RUN: env MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
13 // RUN: FileCheck %s --check-prefix=CHECK-PER-STACK --check-prefix=CHECK-%short-stack < %t.out
15 // RUN: env MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
16 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
19 // RUN: %clangxx_msan -DSTACK -fsanitize-memory-track-origins=2 -O3 %s -o %t
21 // RUN: env MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
22 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
24 // RUN: env MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
25 // RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
27 // RUN: env MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
28 // RUN: FileCheck %s --check-prefix=CHECK-PER-STACK --check-prefix=CHECK-%short-stack < %t.out
30 // RUN: env MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
31 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
33 // Heap origin, with calls.
34 // RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -O3 %s -o %t
36 // RUN: env MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
37 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
39 // RUN: env MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
40 // RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
42 // RUN: env MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
43 // RUN: FileCheck %s --check-prefix=CHECK-PER-STACK --check-prefix=CHECK-%short-stack < %t.out
45 // RUN: env MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
46 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
48 // Stack origin, with calls.
49 // RUN: %clangxx_msan -DSTACK -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -O3 %s -o %t
51 // RUN: env MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
52 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
54 // RUN: env MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
55 // RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
57 // RUN: env MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
58 // RUN: FileCheck %s --check-prefix=CHECK-PER-STACK --check-prefix=CHECK-%short-stack < %t.out
60 // RUN: env MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
61 // RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
68 static char *buf
, *cur
, *end
;
73 char *volatile p
= stackbuf
;
82 for (p
= cur
- 1; p
>= buf
; --p
)
86 size_t write_sz
= p
- buf
+ 1;
87 // write(2, buf, write_sz);
88 memmove(buf
, p
+ 1, end
- p
- 1);
93 void buffered_write(const char *p
, size_t sz
) {
95 size_t copy_sz
= end
- cur
;
96 if (sz
< copy_sz
) copy_sz
= sz
;
97 memcpy(cur
, p
, copy_sz
);
105 buffered_write("a\n", 2);
109 buffered_write("a\n", 2);
113 buffered_write("a\n", 2);
118 for (int i
= 0; i
< 2000; ++i
) {
126 // CHECK7: WARNING: MemorySanitizer: use-of-uninitialized-value
127 // CHECK7-NOT: Uninitialized value was stored to memory at
128 // CHECK7: Uninitialized value was stored to memory at
129 // CHECK7-NOT: Uninitialized value was stored to memory at
130 // CHECK7: Uninitialized value was stored to memory at
131 // CHECK7-NOT: Uninitialized value was stored to memory at
132 // CHECK7: Uninitialized value was stored to memory at
133 // CHECK7-NOT: Uninitialized value was stored to memory at
134 // CHECK7: Uninitialized value was stored to memory at
135 // CHECK7-NOT: Uninitialized value was stored to memory at
136 // CHECK7: Uninitialized value was stored to memory at
137 // CHECK7-NOT: Uninitialized value was stored to memory at
138 // CHECK7: Uninitialized value was stored to memory at
139 // CHECK7-NOT: Uninitialized value was stored to memory at
140 // CHECK7: Uninitialized value was created
142 // CHECK2: WARNING: MemorySanitizer: use-of-uninitialized-value
143 // CHECK2-NOT: Uninitialized value was stored to memory at
144 // CHECK2: Uninitialized value was stored to memory at
145 // CHECK2-NOT: Uninitialized value was stored to memory at
146 // CHECK2: Uninitialized value was created
148 // For architectures with short stack all the stacks in the chain are same
149 // because the stack trace does not contain frames upto the functions fn1, fn2,
150 // fn3 from where the uninitialized stores actually originate. Since we report
151 // uninitialized value store once for each stack frame
152 // (origin_history_per_stack_limit = 1) we expect only one instance of
153 // "Uninitialized value was stored to memory at".
155 // CHECK-PER-STACK: WARNING: MemorySanitizer: use-of-uninitialized-value
156 // CHECK-PER-STACK: Uninitialized value was stored to memory at
157 // CHECK-SHORT-STACK: in __msan_memmove
158 // CHECK-FULL-STACK: in fn3
159 // CHECK-FULL-STACK: Uninitialized value was stored to memory at
160 // CHECK-FULL-STACK: in fn2
161 // CHECK-FULL-STACK: Uninitialized value was stored to memory at
162 // CHECK-FULL-STACK: in fn1
163 // CHECK-PER-STACK: Uninitialized value was created
165 // CHECK-UNLIMITED: WARNING: MemorySanitizer: use-of-uninitialized-value
166 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
167 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
168 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
169 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
170 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
171 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
172 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
173 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
174 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
175 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
176 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
177 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
178 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
179 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
180 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
181 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
182 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
183 // CHECK-UNLIMITED: Uninitialized value was stored to memory at
184 // CHECK-UNLIMITED: Uninitialized value was created