<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121427>121427</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Compiler should issue a warning when passing function pointers not marked noexcept to functions where throwing an exception in a callback function is undefined behavior
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ryao
</td>
</tr>
</table>
<pre>
The unity blog describes an interesting bug that occurred on Windows:
https://unity.com/blog/engine-platform/debugging-memory-debugging-memory-corruption-who-wrote-2-into-my-stack-who-the-hell
Thread A blocked in select(), which is a wrapper around WaitForSingleObjectEx(). Thread B called QueueUserAPC(), which interrupted Thread A to run a callback function. The callback function then threw an exception, causing the stack to unwind, while the kernel had yet to respond to the select() call. When it finally did respond to the select call, the stack frame was gone due to C++ stack unwinding, and WAIT_TIMEOUT (0x00000102L) was written to the stack, causing stack corruption.
QueueUserAPC() is a C ABI function and thus invoking a C++ exception in it triggers undefined behavior. The compiler should issue a warning when passing a function pointer not marked noexcept to a C ABI function, but does not:
https://godbolt.org/z/7hKnrW1xe
Similarly, the compiler should warn about passing a function pointer to a function not marked noexcept to a function marked noexcept, but does not:
https://godbolt.org/z/bMab4a4YG
There is also a bug filed with GCC, which similarly does not issue a warning:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118263
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVU2PGjkQ_TXmUmrUbSDAoQ8zJESj3Si7ykSjPUVuu2g7Y-yWP6aH_PpVGQayTGalXYT4aLtevfeqyhYxmt4htmxxyxbvJyIn7UMbDsJPOq8O7b1GyM6kA3TW96AwymA6jCAcGJcwYEzG9dDlHpIWCbyUOQRU4B08GKf8GNnshtX01ikN5R_fMr4tsFPp94xvCZzxLbreOKwGK9LOB1pQ2OW-N66v9rj34VC9eiB9CHlIxrtq1L4ag09Y8cq45Kv9oYpJyMe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