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