2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clangxx_asan %s -o %t && %run %t
|
2013-02-20 18:43:05 +08:00
|
|
|
// http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed).
|
2014-05-01 05:34:17 +08:00
|
|
|
// BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t
|
2014-02-13 22:37:25 +08:00
|
|
|
//
|
|
|
|
// Android builds with static libstdc++ by default.
|
|
|
|
// XFAIL: android
|
|
|
|
|
2014-05-28 21:06:14 +08:00
|
|
|
// Clang doesn't support exceptions on Windows yet.
|
|
|
|
// XFAIL: win32
|
|
|
|
|
2013-02-20 18:43:05 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
static volatile int zero = 0;
|
|
|
|
inline void pretend_to_do_something(void *x) {
|
|
|
|
__asm__ __volatile__("" : : "r" (x) : "memory");
|
|
|
|
}
|
|
|
|
|
2013-02-26 15:01:06 +08:00
|
|
|
__attribute__((noinline, no_sanitize_address))
|
2013-02-20 18:43:05 +08:00
|
|
|
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();
|
2013-02-20 19:06:07 +08:00
|
|
|
} catch(int a) {
|
2013-02-20 18:43:05 +08:00
|
|
|
fprintf(stderr, "a = %d\n", a);
|
|
|
|
}
|
|
|
|
CheckStack();
|
|
|
|
}
|