GCC builtins in LDC - compiler interoperability
kinke
noone at nowhere.com
Thu Jul 16 00:06:49 UTC 2020
On Wednesday, 15 July 2020 at 23:31:39 UTC, Cecil Ward wrote:
> Oh, shame. There’s no __builtin_unreachable in ldc? I wonder if
> I could work around this with LDC then.
With D / LDC, there's almost always a workaround. In this case,
using inline LLVM IR (as 'unreachable' is an IR instruction for
LLVM):
-----
bool foo() nothrow;
void unreachable()
{
import ldc.llvmasm;
// due to a current LDC bug, a dummy parameter is required
__ir!(`unreachable`, void, int)(0);
}
int bar()
{
int r = 123;
if (foo())
{
r = 456;
unreachable();
}
return r;
}
-----
With -O, bar() is optimized to a `return 123`.
More information about the digitalmars-d-ldc
mailing list