[llvm-commits] [compiler-rt] r163381 - in /compiler-rt/trunk/lib/asan/lit_tests: Helpers/initialization-bug-extra2.cc initialization-bug.cc
Alexey Samsonov
samsonov at google.com
Fri Sep 7 02:24:29 PDT 2012
Author: samsonov
Date: Fri Sep 7 04:24:29 2012
New Revision: 163381
URL: http://llvm.org/viewvc/llvm-project?rev=163381&view=rev
Log:
[ASan] hack initialization-bug test so that it stably passes on both Linux and Mac: make the bug appear independent of the translation unit order
Added:
compiler-rt/trunk/lib/asan/lit_tests/Helpers/initialization-bug-extra2.cc
Modified:
compiler-rt/trunk/lib/asan/lit_tests/initialization-bug.cc
Added: compiler-rt/trunk/lib/asan/lit_tests/Helpers/initialization-bug-extra2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Helpers/initialization-bug-extra2.cc?rev=163381&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Helpers/initialization-bug-extra2.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/Helpers/initialization-bug-extra2.cc Fri Sep 7 04:24:29 2012
@@ -0,0 +1,6 @@
+// 'z' is dynamically initialized global from different TU.
+extern int z;
+int __attribute__((noinline)) initY() {
+ return z + 1;
+}
+int y = initY();
Modified: compiler-rt/trunk/lib/asan/lit_tests/initialization-bug.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/initialization-bug.cc?rev=163381&r1=163380&r2=163381&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/initialization-bug.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/initialization-bug.cc Fri Sep 7 04:24:29 2012
@@ -1,33 +1,46 @@
// Test to make sure basic initialization order errors are caught.
-// RUN: %clangxx_asan -m64 -O0 %s %p/Helpers/initialization-bug-extra.cc\
+// RUN: %clangxx_asan -m64 -O0 %s %p/Helpers/initialization-bug-extra2.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: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-bug-extra2.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;
+#include <cstdio>
+
+// The structure of the test is:
+// "x", "y", "z" are dynamically initialized globals.
+// Value of "x" depends on "y", value of "y" depends on "z".
+// "x" and "z" are defined in this TU, "y" is defined in another one.
+// Thus we shoud stably report initialization order fiasco independently of
+// the translation unit order.
+
+int initZ() {
+ return 5;
+}
+int z = initZ();
// '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.
+extern int y;
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.*}}
+ // CHECK: {{0x.* is located 0 bytes inside of global variable .*(y|z).*}}
}
-
// This initializer begins our initialization order problems.
static int x = initX();
-// ASan should have caused an exit before main runs.
int main() {
- return -1;
+ // ASan should have caused an exit before main runs.
+ printf("PASS\n");
+ // CHECK-NOT: PASS
+ return 0;
}
More information about the llvm-commits
mailing list