rahul
rahul

Reputation: 79

Error in exception handling with LLVM

I am trying to compile C++ code with CLANG++ as front end and backend as LLVM. The version is 3.0. There seems to be a problem with exception handling. Whenever the code throws an exception, the program just terminates with message that "Termination after throwing an exception".

Here is one of the sample code I tried with CLANG ++ .

struct A {};
struct B : virtual A {};
struct C : virtual A {};
struct D : virtual A {};
struct E : private B, public C, private D {};

extern "C" void abort ();

void fne (E *e)
{
  throw e;
}

void check(E *e)
{
  int caught;

  caught = 0;
  try { fne(e); }
  catch(A *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(e); }
  catch(B *p) { abort ();}
  catch(...) { caught = 1; }
  if (!caught) abort();

  caught = 0;
  try { fne(e); }
  catch(C *p) { caught = 1; if (p != e) abort();}
  catch(...) { abort(); }
  if (!caught) abort();

  caught = 0;
  try { fne(e); }
  catch(D *p) { abort ();}
  catch(...) { caught = 1; }
  if (!caught) abort();

  return;
}

int main ()
{
  E e;

  check (&e);
  check ((E *)0);

  return 0;
}

I am quite new to LLVM so do not have much idea about it. Also does it have anything related to Exception Handling table generation by LLVM. The above problem continues for any code. I have compiled the above code on Linux machine. Also I tried putting printf on every catch clause but no response. So it seems that when exception was thrown , no matching catch was found for the exception and it led to call of terminate funciton

Upvotes: 4

Views: 815

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

Seeing your other question... If you're on arm/linux - then such result is expected. The support for EH is not finished there, so, it might be arbitrary broken.

Upvotes: 2

Related Questions