1 // Test to make sure basic initialization order errors are caught.
2 // Check that on Linux initialization order bugs are caught
3 // independently on order in which we list source files (if we specify
4 // strict init-order checking).
6 // RUN: %clangxx_asan -O0 %s %p/../Helpers/initialization-bug-extra.cpp -o %t
7 // RUN: %env_asan_opts=strict_init_order=true not %run %t 2>&1 | FileCheck %s
8 // RUN: %clangxx_asan -O0 %p/../Helpers/initialization-bug-extra.cpp %s -o %t
9 // RUN: %env_asan_opts=strict_init_order=true not %run %t 2>&1 | FileCheck %s
11 // Do not test with optimization -- the error may be optimized away.
15 // 'y' is a dynamically initialized global residing in a different TU. This
16 // dynamic initializer will read the value of 'y' before main starts. The
17 // result is undefined behavior, which should be caught by initialization order
20 int __attribute__((noinline
)) initX() {
22 // CHECK: {{AddressSanitizer: initialization-order-fiasco}}
23 // CHECK: {{READ of size .* at 0x.* thread T0}}
24 // CHECK: {{#0 0x.* in .*initX.* .*initialization-bug-any-order.cpp:}}[[@LINE-3]]
25 // CHECK: {{0x.* is located 0 bytes inside of global variable .*y.*}}
28 // This initializer begins our initialization order problems.
29 static int x
= initX();
32 // ASan should have caused an exit before main runs.