blob: 783c7894d00278d58020f6804bcd6097159070cc [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// A collection of various initializers which shouldn't trip up initialization
2// order checking. If successful, this will just return 0.
3
Stephen Hines6a211c52014-07-21 00:49:56 -07004// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cc -o %t
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08005// RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
Stephen Hines6a211c52014-07-21 00:49:56 -07006// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cc -o %t
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08007// RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
Stephen Hines6a211c52014-07-21 00:49:56 -07008// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cc -o %t
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08009// RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
Stephen Hines6a211c52014-07-21 00:49:56 -070010// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cc -o %t
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080011// RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
Stephen Hines2d1fdb22014-05-28 23:58:16 -070012
13// Simple access:
14// Make sure that accessing a global in the same TU is safe
15
16bool condition = true;
17int initializeSameTU() {
18 return condition ? 0x2a : 052;
19}
20int sameTU = initializeSameTU();
21
22// Linker initialized:
23// Check that access to linker initialized globals originating from a different
24// TU's initializer is safe.
25
26int A = (1 << 1) + (1 << 3) + (1 << 5), B;
27int getAB() {
28 return A * B;
29}
30
31// Function local statics:
32// Check that access to function local statics originating from a different
33// TU's initializer is safe.
34
35int countCalls() {
36 static int calls;
37 return ++calls;
38}
39
40// Trivial constructor, non-trivial destructor.
41struct StructWithDtor {
42 ~StructWithDtor() { }
43 int value;
44};
45StructWithDtor struct_with_dtor;
46int getStructWithDtorValue() { return struct_with_dtor.value; }
47
48int main() { return 0; }