4

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

Dan D.
  • 73,243
  • 15
  • 104
  • 123
rahul
  • 79
  • 4
  • 1
    Read this answer's **Note** at bottom : http://stackoverflow.com/a/8883505/733152 – Mr.Anubis Jan 29 '12 at 17:39
  • You left out the most important point - which OS? – Xeo Jan 29 '12 at 17:48
  • I have modified the comment .On linux machine – rahul Jan 29 '12 at 18:20
  • @rahul: instead of calling `abort`, it would be more interesting to print a message, so that you could in a single test know which path is taken in each case. Note that I am not so sure about the behavior of throwing a null pointer when it comes to determining its bases... it might well invoke undefined behavior. – Matthieu M. Jan 29 '12 at 18:33
  • @MatthieuM. already tried putting comment in every catch clause but it seems the exception is not caught only but is infact directly send to the terminate function i.e. it is not finding any matching catch for the exception. – rahul Jan 29 '12 at 19:32
  • I'm surprised this works on any compiler, especially the second check call. Is throwing a NULL pointer to a polymorphic object defined behavior? – ergosys Jan 29 '12 at 20:34
  • Can you try [this slightly modified test code](http://ideone.com/ZUJUb) and report the output (if any) back? Clang 3.1 TOT on Debian Squeeze 6.0.3 prints nothing and finishs without a call to `terminate`. – Xeo Jan 29 '12 at 20:41

1 Answers1

2

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.

Anton Korobeynikov
  • 9,074
  • 25
  • 28