| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 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 -m64 -O0 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 5 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 6 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 7 | // RUN: %clangxx_asan -m64 -O1 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 8 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 9 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 10 | // RUN: %clangxx_asan -m64 -O2 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 11 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 12 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 13 | // RUN: %clangxx_asan -m64 -O3 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 14 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 15 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 16 | // RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 17 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 18 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 19 | // RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 20 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 21 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 22 | // RUN: %clangxx_asan -m32 -O1 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 23 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 24 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 25 | // RUN: %clangxx_asan -m32 -O2 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 26 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 27 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 28 | // RUN: %clangxx_asan -m32 -O3 %s %p/Helpers/initialization-nobug-extra.cc\ |
| Alexey Samsonov | 566c0a1 | 2013-03-14 11:49:40 +0000 | [diff] [blame] | 29 | // RUN: --std=c++11 -fsanitize=init-order -o %t |
| 30 | // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1 |
| Kostya Serebryany | 5f799c7 | 2012-09-05 09:07:02 +0000 | [diff] [blame] | 31 | |
| 32 | // Simple access: |
| 33 | // Make sure that accessing a global in the same TU is safe |
| 34 | |
| 35 | bool condition = true; |
| 36 | int initializeSameTU() { |
| 37 | return condition ? 0x2a : 052; |
| 38 | } |
| 39 | int 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 | |
| 45 | int A = (1 << 1) + (1 << 3) + (1 << 5), B; |
| 46 | int 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 | |
| 54 | int 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 | |
| 65 | class Integer { |
| 66 | private: |
| 67 | int value; |
| 68 | |
| 69 | public: |
| 70 | constexpr Integer(int x = 0) : value(x) {} |
| 71 | int getValue() {return value;} |
| 72 | }; |
| 73 | Integer coolestInteger(42); |
| 74 | int getCoolestInteger() { return coolestInteger.getValue(); } |
| 75 | |
| 76 | int main() { return 0; } |