Skip to content

Commit

Permalink
core.builtins: Fix return value of likely/unlikely
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ibuclaw authored and thewilsonator committed Jan 10, 2025
1 parent 12d4f3e commit 1260642
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions druntime/src/core/builtins.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1260642

Please sign in to comment.