blob: 93df993241c861fbdb00ce28b1cb8bf4a2866cb0 [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\
Alexey Samsonov566c0a12013-03-14 11:49:40 +00005// RUN: --std=c++11 -fsanitize=init-order -o %t
6// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +00007// RUN: %clangxx_asan -m64 -O1 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +00008// RUN: --std=c++11 -fsanitize=init-order -o %t
9// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000010// RUN: %clangxx_asan -m64 -O2 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000011// RUN: --std=c++11 -fsanitize=init-order -o %t
12// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000013// RUN: %clangxx_asan -m64 -O3 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000014// RUN: --std=c++11 -fsanitize=init-order -o %t
15// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000016// RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000017// RUN: --std=c++11 -fsanitize=init-order -o %t
18// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000019// RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000020// RUN: --std=c++11 -fsanitize=init-order -o %t
21// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000022// RUN: %clangxx_asan -m32 -O1 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000023// RUN: --std=c++11 -fsanitize=init-order -o %t
24// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000025// RUN: %clangxx_asan -m32 -O2 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000026// RUN: --std=c++11 -fsanitize=init-order -o %t
27// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000028// RUN: %clangxx_asan -m32 -O3 %s %p/Helpers/initialization-nobug-extra.cc\
Alexey Samsonov566c0a12013-03-14 11:49:40 +000029// RUN: --std=c++11 -fsanitize=init-order -o %t
30// RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
Kostya Serebryany5f799c72012-09-05 09:07:02 +000031
32// Simple access:
33// Make sure that accessing a global in the same TU is safe
34
35bool condition = true;
36int initializeSameTU() {
37 return condition ? 0x2a : 052;
38}
39int sameTU = initializeSameTU();
40
41// Linker initialized:
42// Check that access to linker initialized globals originating from a different
43// TU's initializer is safe.
44
45int A = (1 << 1) + (1 << 3) + (1 << 5), B;
46int getAB() {
47 return A * B;
48}
49
50// Function local statics:
51// Check that access to function local statics originating from a different
52// TU's initializer is safe.
53
54int countCalls() {
55 static int calls;
56 return ++calls;
57}
58
59// Constexpr:
60// We need to check that a global variable initialized with a constexpr
61// constructor can be accessed during dynamic initialization (as a constexpr
62// constructor implies that it was initialized during constant initialization,
63// not dynamic initialization).
64
65class Integer {
66 private:
67 int value;
68
69 public:
70 constexpr Integer(int x = 0) : value(x) {}
71 int getValue() {return value;}
72};
73Integer coolestInteger(42);
74int getCoolestInteger() { return coolestInteger.getValue(); }
75
76int main() { return 0; }