Open SvizelPritula opened 1 year ago
Confirmed: https://godbolt.org/z/75z4zMTnd CC @AaronBallman
@llvm/issue-subscribers-clang-frontend
This is known problem with unreachable: https://github.com/llvm/llvm-project/issues/48943
Right now it does not seem like anyone has the bandwidth to tackle this issue.
I feel like this is not exactly a duplicate but if the OP feels like it is a close enough then feel free to close.
@llvm/issue-subscribers-clang-codegen
Using
__builtin_unreachable
, it's possible to create a functiona
that compiles to zero Assembly instructions, like this:With
-O1
or higher this compiles to:The function
a
is pretty useless, since calling it will unconditionally result in undefined behaviour. It is, however, possible to take its address, like this:Executing this will reveal that
ap
andbp
have identical values, sincea
andb
have the same address. However, it will also show thatap == bp
is false, which contradicts that.My guess is that some optimization pass assumes that different functions have different addresses, which is required by the C standard.
This bug is unlikely to happen in real programs, since: a) few programs have functions that have unconditionally undefined behaviour, b) even fewer programs will take the address of such a function, and c) fewer still programs compare function pointers.
__builtin_unreachable
can also be replaced by other statements with undefined behaviour, such asfor (int i=0; i>=0; i++);
.Tested with
clang
andclang++
15.0.7 with an optimization level of 1.