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 12 int 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(p + 4*3, 4); 19 __msan_allocated_memory(p + 4*4, 4); 20 __msan_allocated_memory(p + 4*5, 4); 21 __msan_allocated_memory(p + 4*6, 4); 22 __msan_allocated_memory(p + 4*7, 4); 23 __msan_allocated_memory(p + 4*8, 4); 24 __msan_allocated_memory(p + 4*9, 4); 25 __msan_allocated_memory(p + 4*10, 4); 26 __msan_allocated_memory(p + 4*11, 4); 27 __msan_allocated_memory(p + 4*12, 4); 28 __msan_allocated_memory(p + 4*13, 4); 29 __msan_allocated_memory(p + 4*14, 4); 30 __msan_allocated_memory(p + 4*15, 4); 31 __msan_allocated_memory(p + 4*16, 4); 32 __msan_allocated_memory(p + 4*17, 4); 33 __msan_allocated_memory(p + 4*18, 4); 34 __msan_allocated_memory(p + 4*19, 4); 35 __msan_allocated_memory(p + 4*20, 4); 36 __msan_allocated_memory(p + 4*21, 4); 37 __msan_allocated_memory(p + 4*22, 4); 38 __msan_allocated_memory(p + 4*23, 4); 39 __msan_allocated_memory(p + 4*24, 4); 40 __msan_allocated_memory(p + 4*25, 4); 41 __msan_allocated_memory(p + 4*26, 4); 42 __msan_allocated_memory(p + 4*27, 4); 43 __msan_allocated_memory(p + 4*28, 4); 44 __msan_allocated_memory(p + 4*29, 4); 45 __msan_allocated_memory(p + 4*30, 4); 46 __msan_allocated_memory(p + 4*31, 4); 47 48 p[19] = x; 49 50 __msan_print_shadow(p+5, 297); 51 delete[] p; 52 return 0; 53 } 54 55 // CHECK: Shadow map of [{{.*}}), 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.cc: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.cc: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.cc:48 109 // CHECK-ORIGINS: Uninitialized value was created by an allocation of 'x' in the stack frame of function 'main' 110 // CHECK-ORIGINS: #0 {{.*}} in main{{.*}}msan_print_shadow.cc:12 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.cc: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.cc:42 123