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
8typedef 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.
12extern "C" FPTR __xi_a, __xi_z;
13
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(format: "Number of nonzero CRT initializers: %u\n", count);
24// CHECK: Number of nonzero CRT initializers
25}
26
27void call_me_maybe() {}
28
29#pragma data_seg(".CRT$XIB")
30// Add an initializer that shouldn't get its own redzone.
31FPTR run_on_startup = call_me_maybe;
32

source code of compiler-rt/test/asan/TestCases/Windows/crt_initializers.cpp