[PATCH] D39901: ASAN lit support for LTO testing and add back ThinLTO test
Teresa Johnson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 07:42:23 PST 2017
tejohnson created this revision.
Herald added subscribers: eraman, inglorion, mehdi_amini, kubamracek.
Adds LTO support similar to test/asan/lit.cfg, modeled on the support in
compiler-rt/test/profile/lit.cfg.
Adds back reverted ThinLTO test using that support.
https://reviews.llvm.org/D39901
Files:
test/asan/TestCases/contiguous_container_crash_thinlto.cc
test/asan/lit.cfg
Index: test/asan/lit.cfg
===================================================================
--- test/asan/lit.cfg
+++ test/asan/lit.cfg
@@ -95,13 +95,20 @@
win_runtime_feature = "win32-static-asan"
config.available_features.add(win_runtime_feature)
-def build_invocation(compile_flags):
- return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
+def build_invocation(compile_flags, with_lto = False):
+ lto_flags = []
+ lto_prefix = []
+ if with_lto and config.lto_supported:
+ lto_flags += config.lto_flags
+ lto_prefix += config.lto_launch
+ return " " + " ".join(lto_prefix + [config.compile_wrapper, config.clang] + lto_flags + compile_flags) + " "
config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
config.substitutions.append( ("%clang_asan ", build_invocation(clang_asan_cflags)) )
config.substitutions.append( ("%clangxx_asan ", build_invocation(clang_asan_cxxflags)) )
+config.substitutions.append( ("%clang_lto_asan ", build_invocation(clang_asan_cflags, True)) )
+config.substitutions.append( ("%clangxx_lto_asan ", build_invocation(clang_asan_cxxflags, True)) )
config.substitutions.append( ("%shared_libasan", "libclang_rt.asan-%s.so" % config.target_arch))
if config.asan_dynamic:
config.substitutions.append( ("%clang_asan_static ", build_invocation(clang_asan_static_cflags)) )
Index: test/asan/TestCases/contiguous_container_crash_thinlto.cc
===================================================================
--- /dev/null
+++ test/asan/TestCases/contiguous_container_crash_thinlto.cc
@@ -0,0 +1,55 @@
+// RUN: %clangxx_lto_asan -flto=thin -O %s -o %t.thinlto
+// RUN: not %run %t.thinlto crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
+// RUN: not %run %t.thinlto bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s
+// RUN: not %run %t.thinlto bad-alignment 2>&1 | FileCheck --check-prefix=CHECK-BAD-ALIGNMENT %s
+// RUN: %env_asan_opts=detect_container_overflow=0 %run %t.thinlto crash
+//
+// Test crash due to __sanitizer_annotate_contiguous_container.
+
+// REQUIRES: lto
+
+#include <assert.h>
+#include <string.h>
+
+extern "C" {
+void __sanitizer_annotate_contiguous_container(const void *beg, const void *end,
+ const void *old_mid,
+ const void *new_mid);
+} // extern "C"
+
+static volatile int one = 1;
+
+int TestCrash() {
+ long t[100];
+ t[60] = 0;
+ __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
+ &t[0] + 50);
+// CHECK-CRASH: AddressSanitizer: container-overflow
+// CHECK-CRASH: if you don't care about these errors you may set ASAN_OPTIONS=detect_container_overflow=0
+ return (int)t[60 * one]; // Touches the poisoned memory.
+}
+
+void BadBounds() {
+ long t[100];
+// CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
+ __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101,
+ &t[0] + 50);
+}
+
+void BadAlignment() {
+ int t[100];
+// CHECK-BAD-ALIGNMENT: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
+// CHECK-BAD-ALIGNMENT: ERROR: beg is not aligned by 8
+ __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[1] + 10,
+ &t[0] + 50);
+}
+
+int main(int argc, char **argv) {
+ assert(argc == 2);
+ if (!strcmp(argv[1], "crash"))
+ return TestCrash();
+ else if (!strcmp(argv[1], "bad-bounds"))
+ BadBounds();
+ else if (!strcmp(argv[1], "bad-alignment"))
+ BadAlignment();
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39901.122436.patch
Type: text/x-patch
Size: 3801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171110/6f04805a/attachment.bin>
More information about the llvm-commits
mailing list