blob: cd68b135be32c00ed2eeb8454d2e2d14dbfb6c45 [file] [log] [blame]
Kostya Serebryany5f799c72012-09-05 09:07:02 +00001// 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 -m64 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
5// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
6// RUN: %clangxx_asan -m64 -O1 %s %p/Helpers/initialization-nobug-extra.cc\
7// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
8// RUN: %clangxx_asan -m64 -O2 %s %p/Helpers/initialization-nobug-extra.cc\
9// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
10// RUN: %clangxx_asan -m64 -O3 %s %p/Helpers/initialization-nobug-extra.cc\
11// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
12// RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
13// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
14// RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
15// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
16// RUN: %clangxx_asan -m32 -O1 %s %p/Helpers/initialization-nobug-extra.cc\
17// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
18// RUN: %clangxx_asan -m32 -O2 %s %p/Helpers/initialization-nobug-extra.cc\
19// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
20// RUN: %clangxx_asan -m32 -O3 %s %p/Helpers/initialization-nobug-extra.cc\
21// RUN: --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
22
23// Simple access:
24// Make sure that accessing a global in the same TU is safe
25
26bool condition = true;
27int initializeSameTU() {
28 return condition ? 0x2a : 052;
29}
30int sameTU = initializeSameTU();
31
32// Linker initialized:
33// Check that access to linker initialized globals originating from a different
34// TU's initializer is safe.
35
36int A = (1 << 1) + (1 << 3) + (1 << 5), B;
37int getAB() {
38 return A * B;
39}
40
41// Function local statics:
42// Check that access to function local statics originating from a different
43// TU's initializer is safe.
44
45int countCalls() {
46 static int calls;
47 return ++calls;
48}
49
50// Constexpr:
51// We need to check that a global variable initialized with a constexpr
52// constructor can be accessed during dynamic initialization (as a constexpr
53// constructor implies that it was initialized during constant initialization,
54// not dynamic initialization).
55
56class Integer {
57 private:
58 int value;
59
60 public:
61 constexpr Integer(int x = 0) : value(x) {}
62 int getValue() {return value;}
63};
64Integer coolestInteger(42);
65int getCoolestInteger() { return coolestInteger.getValue(); }
66
67int main() { return 0; }