xref: /llvm-project/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp (revision c7d4d39b9b2c31968521f2271e6e6aadec902df8)
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 
14 extern int y;
15 
16 void __attribute__((constructor)) ctor() {
17   printf("%d\n", y);
18   // CHECK: AddressSanitizer: initialization-order-fiasco
19 }
20 
21 int main() {
22   // ASan should have caused an exit before main runs.
23   printf("PASS\n");
24   // CHECK-NOT: PASS
25   return 0;
26 }
27