1*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t >%t.out 2>&1
2*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-ORIGINS < %t.out
3*7c3d14c8STreehugger Robot
4*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 -g %s -o %t && %run %t >%t.out 2>&1
5*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ORIGINS < %t.out
6*7c3d14c8STreehugger Robot
7*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O0 -g %s -o %t && %run %t >%t.out 2>&1
8*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ORIGINS --check-prefix=CHECK-ORIGINS-2 < %t.out
9*7c3d14c8STreehugger Robot
10*7c3d14c8STreehugger Robot #include <sanitizer/msan_interface.h>
11*7c3d14c8STreehugger Robot
main(void)12*7c3d14c8STreehugger Robot int main(void) {
13*7c3d14c8STreehugger Robot char volatile x;
14*7c3d14c8STreehugger Robot char *p = new char[320];
15*7c3d14c8STreehugger Robot p[2] = p[5] = 1;
16*7c3d14c8STreehugger Robot p[8] = p[9] = p[10] = p[11] = p[12] = 2;
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*3, 4);
19*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*4, 4);
20*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*5, 4);
21*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*6, 4);
22*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*7, 4);
23*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*8, 4);
24*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*9, 4);
25*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*10, 4);
26*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*11, 4);
27*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*12, 4);
28*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*13, 4);
29*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*14, 4);
30*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*15, 4);
31*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*16, 4);
32*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*17, 4);
33*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*18, 4);
34*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*19, 4);
35*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*20, 4);
36*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*21, 4);
37*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*22, 4);
38*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*23, 4);
39*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*24, 4);
40*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*25, 4);
41*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*26, 4);
42*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*27, 4);
43*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*28, 4);
44*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*29, 4);
45*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*30, 4);
46*7c3d14c8STreehugger Robot __msan_allocated_memory(p + 4*31, 4);
47*7c3d14c8STreehugger Robot
48*7c3d14c8STreehugger Robot p[19] = x;
49*7c3d14c8STreehugger Robot
50*7c3d14c8STreehugger Robot __msan_print_shadow(p+5, 297);
51*7c3d14c8STreehugger Robot delete[] p;
52*7c3d14c8STreehugger Robot return 0;
53*7c3d14c8STreehugger Robot }
54*7c3d14c8STreehugger Robot
55*7c3d14c8STreehugger Robot // CHECK: Shadow map of [{{.*}}), 297 bytes:
56*7c3d14c8STreehugger Robot
57*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ..00ffff 00000000 ffffffff ffffffff
58*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
59*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
60*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
61*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
62*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
63*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
64*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
65*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
66*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
67*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
68*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
69*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
70*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
71*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
72*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
73*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
74*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff
75*7c3d14c8STreehugger Robot // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffff.... ........
76*7c3d14c8STreehugger Robot
77*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ..00ffff 00000000 ffffffff ffffffff |A . B C|
78*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |D E F G|
79*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |H I J K|
80*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |L M N O|
81*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |P Q R S|
82*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |T U V W|
83*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |X Y Z *|
84*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |* * * A|
85*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
86*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
87*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
88*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
89*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
90*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
91*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
92*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
93*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
94*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff |A A A A|
95*7c3d14c8STreehugger Robot // CHECK-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffff.... ........ |A A A .|
96*7c3d14c8STreehugger Robot
97*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Origin A (origin_id {{.*}}):
98*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Uninitialized value was created by a heap allocation
99*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:14
100*7c3d14c8STreehugger Robot
101*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Origin B (origin_id {{.*}}):
102*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Memory was marked as uninitialized
103*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #0 {{.*}} in __msan_allocated_memory
104*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:18
105*7c3d14c8STreehugger Robot
106*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Origin C (origin_id {{.*}}):
107*7c3d14c8STreehugger Robot // CHECK-ORIGINS-2: Uninitialized value was stored to memory at
108*7c3d14c8STreehugger Robot // CHECK-ORIGINS-2: #0 {{.*}} in main{{.*}}msan_print_shadow.cc:48
109*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Uninitialized value was created by an allocation of 'x' in the stack frame of function 'main'
110*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #0 {{.*}} in main{{.*}}msan_print_shadow.cc:12
111*7c3d14c8STreehugger Robot
112*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Origin D (origin_id {{.*}}):
113*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Memory was marked as uninitialized
114*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #0 {{.*}} in __msan_allocated_memory
115*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:20
116*7c3d14c8STreehugger Robot
117*7c3d14c8STreehugger Robot // ...
118*7c3d14c8STreehugger Robot
119*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Origin Z (origin_id {{.*}}):
120*7c3d14c8STreehugger Robot // CHECK-ORIGINS: Memory was marked as uninitialized
121*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #0 {{.*}} in __msan_allocated_memory
122*7c3d14c8STreehugger Robot // CHECK-ORIGINS: #1 {{.*}} in main{{.*}}msan_print_shadow.cc:42
123