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