diff options
| author | Kostya Serebryany <kcc@google.com> | 2012-09-05 09:07:02 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2012-09-05 09:07:02 +0000 |
| commit | 4d45b9b78461c006fc738b466ced2407d8fa0988 (patch) | |
| tree | 83c4b2ac7eb612c37b349bea077d5df4572fc643 /compiler-rt/lib/asan/lit_tests/initialization-bug.cc | |
| parent | 02b9553bdb6931c78180204dc7f438e4fcc55a37 (diff) | |
| download | bcm5719-llvm-4d45b9b78461c006fc738b466ced2407d8fa0988.tar.gz bcm5719-llvm-4d45b9b78461c006fc738b466ced2407d8fa0988.zip | |
[asan] added tests for asan-initialization-order, patch by Reid Watson
llvm-svn: 163207
Diffstat (limited to 'compiler-rt/lib/asan/lit_tests/initialization-bug.cc')
| -rw-r--r-- | compiler-rt/lib/asan/lit_tests/initialization-bug.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/lit_tests/initialization-bug.cc b/compiler-rt/lib/asan/lit_tests/initialization-bug.cc new file mode 100644 index 00000000000..872b8bff8fd --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/initialization-bug.cc @@ -0,0 +1,33 @@ +// Test to make sure basic initialization order errors are caught. + +// RUN: %clangxx_asan -m64 -O0 %s %p/Helpers/initialization-bug-extra.cc\ +// RUN: -mllvm -asan-initialization-order -o %t && %t 2>&1 \ +// RUN: | %symbolize | FileCheck %s +// RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-bug-extra.cc\ +// RUN: -mllvm -asan-initialization-order -o %t && %t 2>&1 \ +// RUN: | %symbolize | FileCheck %s + +// Do not test with optimization -- the error may be optimized away. + +extern int y; + +// 'y' is a dynamically initialized global residing in a different TU. This +// dynamic initializer will read the value of 'y' before main starts. The +// result is undefined behavior, which should be caught by initialization order +// checking. +int __attribute__((noinline)) initX() { + return y + 1; + // CHECK: {{AddressSanitizer initialization-order-fiasco}} + // CHECK: {{READ of size .* at 0x.* thread T0}} + // CHECK: {{#0 0x.* in .*initX.* .*initialization-bug.cc:19}} + // CHECK: {{0x.* is located 0 bytes inside of global variable .*y.*}} +} + + +// This initializer begins our initialization order problems. +static int x = initX(); + +// ASan should have caused an exit before main runs. +int main() { + return -1; +} |

