[llvm-commits] [compiler-rt] r163379 - /compiler-rt/trunk/lib/asan/lit_tests/Linux/initialization-bug-any-order.cc

Alexey Samsonov samsonov at google.com
Fri Sep 7 02:04:31 PDT 2012


Author: samsonov
Date: Fri Sep  7 04:04:31 2012
New Revision: 163379

URL: http://llvm.org/viewvc/llvm-project?rev=163379&view=rev
Log:
[ASan] add Linux-specific test for initialization order that checks that we find a bug independently of translation units order

Added:
    compiler-rt/trunk/lib/asan/lit_tests/Linux/initialization-bug-any-order.cc

Added: compiler-rt/trunk/lib/asan/lit_tests/Linux/initialization-bug-any-order.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Linux/initialization-bug-any-order.cc?rev=163379&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Linux/initialization-bug-any-order.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/Linux/initialization-bug-any-order.cc Fri Sep  7 04:04:31 2012
@@ -0,0 +1,37 @@
+// Test to make sure basic initialization order errors are caught.
+// Check that on Linux initialization order bugs are caught
+// independently on order in which we list source files.
+
+// 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 -m64 -O0 %p/../Helpers/initialization-bug-extra.cc %s\
+// 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.
+
+#include <cstdio>
+
+// '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-any-order.cc:22}}
+  // CHECK: {{0x.* is located 0 bytes inside of global variable .*y.*}}
+}
+
+// This initializer begins our initialization order problems.
+static int x = initX();
+
+int main() {
+  // 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