1 | // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O0 %s -o %t && not %run %t >%t.out 2>&1 |
2 | // RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-%short-stack %s < %t.out |
3 | // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O2 %s -o %t && not %run %t >%t.out 2>&1 |
4 | // RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-%short-stack %s < %t.out |
5 | |
6 | // This is a regression test: there used to be broken "stored to memory at" |
7 | // stacks with |
8 | // in __msan_memcpy |
9 | // in __msan::MsanReallocate |
10 | // and nothing below that. |
11 | |
12 | #include <stdlib.h> |
13 | int main(int argc, char **argv) { |
14 | char *p = (char *)malloc(size: 100); |
15 | p = (char *)realloc(ptr: p, size: 10000); |
16 | char x = p[50]; |
17 | free(ptr: p); |
18 | return x; |
19 | |
20 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value |
21 | // CHECK: {{#0 0x.* in main .*realloc-large-origin.cpp:}}[[@LINE-3]] |
22 | |
23 | // CHECK: Uninitialized value was stored to memory at |
24 | // CHECK-FULL-STACK: {{#0 0x.* in .*realloc}} |
25 | // CHECK-FULL-STACK: {{#1 0x.* in main .*realloc-large-origin.cpp:}}[[@LINE-10]] |
26 | // CHECK-SHORT-STACK: {{#0 0x.* in .*realloc}} |
27 | |
28 | // CHECK: Uninitialized value was created by a heap allocation |
29 | // CHECK: {{#0 0x.* in .*malloc}} |
30 | // CHECK: {{#1 0x.* in main .*realloc-large-origin.cpp:}}[[@LINE-16]] |
31 | } |
32 | |