<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62025>62025</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
miscompilation - "Illegal instruction" with exception handling in nested functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bigbio2002
</td>
</tr>
</table>
<pre>
The resulting executable from compiling this sample code (from C++ for Dummies, ch. 25) crashes. The output is supposed to be
`
Constructing object a
Constructing object b
Constructing object c
Constructing object d
Destructing object d
Destructing object c
Destructing object b
Int catch
Destructing object a
`
but instead terminates with
`
...
Destructing object b
Int catch
Illegal instruction (core dumped)
`
The code is as follows; I'm unsure what exactly is causing it to crash, but the code is very minimal as-is.
`
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class Obj
{
public:
Obj(char c)
{
label = c;
cout << "Constructing object " << label << endl;
}
~Obj()
{
cout << "Destructing object " << label << endl;
}
protected:
char label;
};
void f1();
void f2();
int f3()
{
Obj a('a');
try
{
Obj b('b');
f1();
}
catch(float f)
{
cout << "Float catch" << endl;
}
catch(int i)
{
cout << "Int catch" << endl;
}
catch(...)
{
cout << string("Generic catch") << endl;
}
}
int main(int nNumberofArgs, char* pszArgs[])
{
f3();
// wait until user is ready before terminating program
// to allow the user to see the program results
//system("PAUSE");
return 0;
}
void f1()
{
try
{
Obj c('c');
f2();
}
catch(string msg)
{
cout << "String catch" << endl;
}
}
void f2()
{
Obj d('d');
throw 10;
}
`
The crash occurs when compiling with Clang++ 10 and 11 as tested on Debian and Termux. It compiles and runs as expected when using g++.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVsuS4rgS_RqxySiHkHl5waIKmhu1uT0R3fMBspTG6pAlhx5NMYv59gnJpgoomKZnY4TyfXSUKe692hvENZm_kPl2wmNorVvXal8ryyhlk9rK4_p7i-DQRx2U2QO-oY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