From 0f08dff1b569b1285992644fe783fc67c39a4209 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 29 Mar 2018 13:53:50 +0000 Subject: [PATCH] [asan] Split the `throw_invoke_test.cc` into a Linux specific variant and the general version to avoid use of libstdc++ on non-Linux platforms. This is motivated by the fact that using `libstdc++` is deprecated on Darwin and maybe removed some day. Differential Revision: https://reviews.llvm.org/D44733 llvm-svn: 328775 --- .../TestCases/Linux/throw_invoke_test_libstdcxx.cc | 48 ++++++++++++++++++++++ .../test/asan/TestCases/throw_invoke_test.cc | 1 - 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 compiler-rt/test/asan/TestCases/Linux/throw_invoke_test_libstdcxx.cc diff --git a/compiler-rt/test/asan/TestCases/Linux/throw_invoke_test_libstdcxx.cc b/compiler-rt/test/asan/TestCases/Linux/throw_invoke_test_libstdcxx.cc new file mode 100644 index 0000000..69d8538 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Linux/throw_invoke_test_libstdcxx.cc @@ -0,0 +1,48 @@ +// This the basically the `throw_invoke_test.cc` test but using libstdc++ +// instead of the default. +// RUN: %clangxx_asan %s -o %t -stdlib=libstdc++ -static-libstdc++ && %run %t + +#include +static volatile int zero = 0; +inline void pretend_to_do_something(void *x) { + __asm__ __volatile__("" : : "r"(x) : "memory"); +} + +__attribute__((noinline)) void ReallyThrow() { + fprintf(stderr, "ReallyThrow\n"); + try { + if (zero == 0) + throw 42; + else if (zero == 1) + throw 1.; + } catch (double x) { + } +} + +__attribute__((noinline)) void Throw() { + int a, b, c, d, e; + pretend_to_do_something(&a); + pretend_to_do_something(&b); + pretend_to_do_something(&c); + pretend_to_do_something(&d); + pretend_to_do_something(&e); + fprintf(stderr, "Throw stack = %p\n", &a); + ReallyThrow(); +} + +__attribute__((noinline)) void CheckStack() { + int ar[100]; + pretend_to_do_something(ar); + for (int i = 0; i < 100; i++) + ar[i] = i; + fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100); +} + +int main(int argc, char **argv) { + try { + Throw(); + } catch (int a) { + fprintf(stderr, "a = %d\n", a); + } + CheckStack(); +} diff --git a/compiler-rt/test/asan/TestCases/throw_invoke_test.cc b/compiler-rt/test/asan/TestCases/throw_invoke_test.cc index e6e91d1..ade8c0c 100644 --- a/compiler-rt/test/asan/TestCases/throw_invoke_test.cc +++ b/compiler-rt/test/asan/TestCases/throw_invoke_test.cc @@ -1,5 +1,4 @@ // RUN: %clangxx_asan %s -o %t && %run %t -// RUN: %clangxx_asan %s -o %t -stdlib=libstdc++ -static-libstdc++ && %run %t #include static volatile int zero = 0; -- 2.7.4