diff options
Diffstat (limited to 'compiler-rt/lib/asan/lit_tests')
-rw-r--r-- | compiler-rt/lib/asan/lit_tests/Helpers/init-order-atexit-extra.cc | 16 | ||||
-rw-r--r-- | compiler-rt/lib/asan/lit_tests/init-order-atexit.cc | 31 |
2 files changed, 47 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/lit_tests/Helpers/init-order-atexit-extra.cc b/compiler-rt/lib/asan/lit_tests/Helpers/init-order-atexit-extra.cc new file mode 100644 index 00000000000..e4189d19d09 --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/Helpers/init-order-atexit-extra.cc @@ -0,0 +1,16 @@ +#include <stdio.h> + +class C { + public: + C() { value = 42; } + ~C() { } + int value; +}; + +C c; + +void AccessC() { + printf("C value: %d\n", c.value); +} + +int main() { return 0; } diff --git a/compiler-rt/lib/asan/lit_tests/init-order-atexit.cc b/compiler-rt/lib/asan/lit_tests/init-order-atexit.cc new file mode 100644 index 00000000000..45f4f17c0cb --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/init-order-atexit.cc @@ -0,0 +1,31 @@ +// Test for the following situation: +// (1) global A is constructed. +// (2) exit() is called during construction of global B. +// (3) destructor of A reads uninitialized global C from another module. +// We do *not* want to report init-order bug in this case. + +// RUN: %clangxx_asan -m64 -O0 %s %p/Helpers/init-order-atexit-extra.cc -o %t +// RUN: ASAN_OPTIONS=check_initialization_order=true:strict_init_order=true %t 2>&1 | FileCheck %s + +#include <stdio.h> +#include <stdlib.h> + +void AccessC(); + +class A { + public: + A() { } + ~A() { AccessC(); printf("PASSED\n"); } + // CHECK-NOT: AddressSanitizer + // CHECK: PASSED +}; + +A a; + +class B { + public: + B() { exit(1); } + ~B() { } +}; + +B b; |