1 // RUN: %clang_cl_asan -Od %s -Fe%t 2 // RUN: %run %t | FileCheck %s 3 4 // This is a test for http://code.google.com/p/address-sanitizer/issues/detail?id=305 5 6 #include <stdio.h> 7 8 typedef void (*FPTR)(); 9 10 // __xi_a and __xi_z are defined in VC/crt/src/crt0dat.c 11 // and are located in .CRT$XIA and .CRT$XIZ respectively. 12 extern "C" FPTR __xi_a, __xi_z; 13 main()14int main() { 15 unsigned count = 0; 16 17 // Iterate through CRT initializers. 18 for (FPTR* it = &__xi_a; it < &__xi_z; ++it) { 19 if (*it) 20 count++; 21 } 22 23 printf("Number of nonzero CRT initializers: %u\n", count); 24 // CHECK: Number of nonzero CRT initializers 25 } 26 call_me_maybe()27void call_me_maybe() {} 28 29 #pragma data_seg(".CRT$XIB") 30 // Add an initializer that shouldn't get its own redzone. 31 FPTR run_on_startup = call_me_maybe; 32