From b36cfc6352df4c5c5005c7a720dbc84894097d11 Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Sat, 28 Mar 2026 09:53:13 +0000 Subject: [PATCH] compiler-rt: work around LLVM not respecting -fno-builtin --- lib/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 index 979a5452a53e3497f48af7bf4abe8af9eb7ed884..bd8e3e28953931f9a85e7e599c9b0184fc432d23 100644 --- 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 -- 2.54.0