<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75856>75856</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
UBSan does not catch incorrect [[noreturn]] annotations if called indirectly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidben
</td>
</tr>
</table>
<pre>
UBSan catches the following invalid program:
```
#include <stdio.h>
[[noreturn]] void nope() {}
int main() {
nope();
printf("This should not run\n");
}
```
```
$ clang++ -fsanitize=undefined -Wno-invalid-noreturn ok.cc && ./a.out
ok.cc:6:3: runtime error: execution reached an unreachable program point
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ok.cc:6:3 in
```
However, it does not catch the following:
```
#include <stdio.h>
[[noreturn]] void nope() {}
void indirect_call(void (*f)()) {
f();
}
int main() {
indirect_call(nope);
printf("This should not run\n");
}
```
```
$ clang++ -fsanitize=undefined -Wno-invalid-noreturn not_ok.cc && ./a.out
This should not run
```
Poking around at the assembly output, it looks like UBSan instruments `[[noreturn]]` failures at the caller and not the callee. Instrumenting at the caller mostly works, and is nice when only the caller was instrumented. But when the function is called through a function pointer that loses the `[[noreturn]]` annotation, it loses this.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2P8kYM_jWTi0VEZhI-DjnAUtQeXqnqdlX19GqSGOLu4EHzAaW_vsoEWHa1XfXWSogoth_PY-exR3tPe0asRbUW1SbTMfTW1Z0-UdcgZ43tLvXL-lkztDq0PXoIPcLOGmPPxHsgPmlDHRyd3Tt9EGolphsxXYnZ9PobX6Uibk3sEIR68qEjm_dC_XD1jv8DhTVbhyE6FtVGVBs4WeqA7RGFXAi5BDFfi_nmEUYc4KCJHwKSHR5gQt2NR0ccdsksf-3Jg-9tNMMZAVxkUT2xkPIR83beh5o-L7SE1mjeC7kWcg2TnddMgf5CoTaRO9w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