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

source code of compiler-rt/test/msan/msan_print_shadow.cpp