brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 2faf3ef Raw
56 lines · cpp
1// RUN: %clangxx_asan %s -o %t && %run %t2// RUN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t3 4// Investigate why it fails with NDK 21.5// UNSUPPORTED: android, MSVC6 7#include "defines.h"8#include <stdio.h>9static volatile int zero = 0;10inline void pretend_to_do_something(void *x) {11  __asm__ __volatile__("" : : "r" (x) : "memory");12}13 14__attribute__((noinline))15void ReallyThrow() {16  fprintf(stderr, "ReallyThrow\n");17  try {18    if (zero == 0)19      throw 42;20    else if (zero == 1)21      throw 1.;22  } catch(double x) {23  }24}25 26__attribute__((noinline))27void Throw() {28  int a, b, c, d, e;29  pretend_to_do_something(&a);30  pretend_to_do_something(&b);31  pretend_to_do_something(&c);32  pretend_to_do_something(&d);33  pretend_to_do_something(&e);34  fprintf(stderr, "Throw stack = %p\n", &a);35  ReallyThrow();36}37 38ATTRIBUTE_NOINLINE39void CheckStack() {40  int ar[100];41  pretend_to_do_something(ar);42  for (int i = 0; i < 100; i++)43    ar[i] = i;44  fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);45}46 47int main(int argc, char** argv) {48  try {49    Throw();50  } catch(int a) {51    fprintf(stderr, "a = %d\n", a);52  }53  CheckStack();54}55 56