1 | // A collection of various initializers which shouldn't trip up initialization |
2 | // order checking. If successful, this will just return 0. |
3 | |
4 | // RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison" |
5 | // RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison" |
6 | // RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison" |
7 | // RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison" |
8 | |
9 | // Simple access: |
10 | // Make sure that accessing a global in the same TU is safe |
11 | |
12 | bool condition = true; |
13 | __attribute__((noinline, weak)) int initializeSameTU() { |
14 | return condition ? 0x2a : 052; |
15 | } |
16 | int sameTU = initializeSameTU(); |
17 | |
18 | // Linker initialized: |
19 | // Check that access to linker initialized globals originating from a different |
20 | // TU's initializer is safe. |
21 | |
22 | int A = (1 << 1) + (1 << 3) + (1 << 5), B; |
23 | int getAB() { |
24 | return A * B; |
25 | } |
26 | |
27 | // Function local statics: |
28 | // Check that access to function local statics originating from a different |
29 | // TU's initializer is safe. |
30 | |
31 | int countCalls() { |
32 | static int calls; |
33 | return ++calls; |
34 | } |
35 | |
36 | // Trivial constructor, non-trivial destructor. |
37 | struct StructWithDtor { |
38 | ~StructWithDtor() { } |
39 | int value; |
40 | }; |
41 | StructWithDtor struct_with_dtor; |
42 | int getStructWithDtorValue() { return struct_with_dtor.value; } |
43 | |
44 | int main() { return 0; } |
45 | |
46 | // CHECK: DynInitPoison |
47 | // CHECK: DynInitPoison |
48 | |
49 | // In general case entire set of DynInitPoison must be followed by at lest one |
50 | // DynInitUnpoison. In some cases we can limit the number of DynInitUnpoison, |
51 | // see initialization-nobug-lld.cpp. |
52 | |
53 | // CHECK: DynInitUnpoison |
54 | |