Open lzaoral opened 2 years ago
The issue is actually more complex than just error(3)
. The same applies to any function (e.g. not just main
) that does not return and is decorated by _Noreturn
function specifier from C11 (the same probably holds for __attribute__((noreturn))
as well). Note that such function will have the noreturn
function attribute in LLVM.
#include <assert.h>
#include <stdlib.h>
#include <stdnoreturn.h>
void test_assert(int arg) {
assert(arg);
}
noreturn void foo(void) {
exit(0);
}
int main(void)
{
test_assert(1);
foo();
}
It's important to check bodies of all such functions though because as C11 says:
If the function declared
_Noreturn
returns, the behaviour is undefined.
So just replacing all undefined
instructions in IR after calls of functions with noreturn
attributes will hide this issue.
Consider the following C program
and slice it like this:
Problem: The sliced bitcode now has a reachable
unreachable
instruction becausetest_assert
will always return:EDIT: typo