From 126064282f25bf1889277db814d98e1ac9a5447a Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Fri, 10 Jan 2025 23:17:04 +0100 Subject: [PATCH] core.builtins: Fix return value of likely/unlikely For both GCC and LLVM, `__builtin_expect` and `llvm_expect` respectively return an integer, not a boolean. This triggers a compiler error as implicit narrow conversions are not allowed. --- druntime/src/core/builtins.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/druntime/src/core/builtins.d b/druntime/src/core/builtins.d index 56e5bc7bede..4e0c6d4d622 100644 --- a/druntime/src/core/builtins.d +++ b/druntime/src/core/builtins.d @@ -94,9 +94,9 @@ else version (DigitalMars) /// Provide static branch and value hints for the LDC/GDC compilers. /// DMD ignores these hints. -pragma(inline, true) bool likely()(bool b) { return expect(b, true); } +pragma(inline, true) bool likely()(bool b) { return !!expect(b, true); } /// ditto -pragma(inline, true) bool unlikely()(bool b) { return expect(b, false); } +pragma(inline, true) bool unlikely()(bool b) { return !!expect(b, false); } /// @nogc nothrow pure @safe unittest