zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit b36cfc6352df4c5c5005c7a720dbc84894097d11 (tree)
parent 2ac47fe314f0a88a2e5ac6c0116392504369b466
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Sat, 28 Mar 2026 09:53:13 +0000

compiler-rt: work around LLVM not respecting -fno-builtin

Diffstat:
Mlib/compiler_rt/mulo.zig | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/compiler_rt/mulo.zig b/lib/compiler_rt/mulo.zig @@ -19,7 +19,12 @@ comptime { inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { overflow.* = 0; const min = math.minInt(ST); - const res: ST = a *% b; + const res: ST = if (ST == i128 and builtin.target.cpu.arch.isWasm()) res: { + // Despite compiler-rt being built with `-fno-builtin`, LLVM still converts this function to + // a call to `__muloti4` on WASM. This is an upstream bug: circumvent it by directly calling + // the "lower-level" compiler-rt routine for this wrapping multiplication. + break :res @import("mulXi3.zig").__multi3(a, b); + } else a *% b; // Hacker's Delight section Overflow subsection Multiplication // case a=-2^{31}, b=-1 problem, because // on some machines a*b = -2^{31} with overflow