From 8381ef203584be0fa260c17127c7a858d27f99ea Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 20 Feb 2013 10:43:05 +0000 Subject: [PATCH] [asan] add test throw_call_test (broken with -static-libstdc++) llvm-svn: 175614 --- compiler-rt/lib/asan/lit_tests/throw_call_test.cc | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 compiler-rt/lib/asan/lit_tests/throw_call_test.cc diff --git a/compiler-rt/lib/asan/lit_tests/throw_call_test.cc b/compiler-rt/lib/asan/lit_tests/throw_call_test.cc new file mode 100644 index 0000000..67aa656 --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/throw_call_test.cc @@ -0,0 +1,46 @@ +// RUN: %clangxx_asan %s -o %t && %t +// http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed). +// BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %t +#include +static volatile int zero = 0; +inline void pretend_to_do_something(void *x) { + __asm__ __volatile__("" : : "r" (x) : "memory"); +} + +__attribute__((noinline, no_address_safety_analysis)) +void ReallyThrow() { + fprintf(stderr, "ReallyThrow\n"); + if (zero == 0) + throw 42; +} + +__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(); +} + -- 2.7.4