1 // RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t 2 // RUN: %clangxx_msan -m64 -O0 -g -DPOSITIVE %s -o %t && not %run %t |& FileCheck %s 3 4 #include <obstack.h> 5 #include <sanitizer/msan_interface.h> 6 #include <stdlib.h> 7 8 static void *obstack_chunk_alloc(size_t sz) { 9 return malloc(sz); 10 } 11 12 static void obstack_chunk_free(void *p) { 13 free(p); 14 } 15 16 int main(void) { 17 obstack obs; 18 obstack_init(&obs); 19 for (size_t sz = 16; sz < 0xFFFF; sz *= 2) { 20 void *p = obstack_alloc(&obs, sz); 21 int data[10] = {0}; 22 obstack_grow(&obs, &data, sizeof(data)); 23 obstack_blank(&obs, sz); 24 obstack_grow(&obs, &data, sizeof(data)); 25 obstack_int_grow(&obs, 13); 26 p = obstack_finish(&obs); 27 #ifdef POSITIVE 28 if (sz == 4096) { 29 __msan_check_mem_is_initialized(p, sizeof(data)); 30 __msan_check_mem_is_initialized(p, sizeof(data) + 1); 31 } 32 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 33 // CHECK: #0 0x{{.*}} in main{{.*}}obstack.cc:[[@LINE-30]] 34 #endif 35 } 36 obstack_free(&obs, 0); 37 } 38