1// RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra.cpp -o %t
2// RUN: %env_asan_opts=check_initialization_order=true:strict_init_order=true not %run %t 2>&1 | FileCheck %s
3
4// Do not test with optimization -- the error may be optimized away.
5
6// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186
7// XFAIL: target={{.*windows-msvc.*}}
8
9// Fails on some Darwin bots, probably iOS.
10// XFAIL: ios
11
12#include <stdio.h>
13
14extern int y;
15
16void __attribute__((constructor)) ctor() {
17 printf(format: "%d\n", y);
18 // CHECK: AddressSanitizer: initialization-order-fiasco
19}
20
21int main() {
22 // ASan should have caused an exit before main runs.
23 printf(format: "PASS\n");
24 // CHECK-NOT: PASS
25 return 0;
26}
27

source code of compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp