zig
zig copied to clipboard
LLVM ERROR: Unable to expand fixed point multipiication.
Zig Version
0.10.0-dev.4519+09236d29b
Steps to Reproduce
That problem will only occur when building for wasm32-freestanding-musl
~~As i don't have a smaller reproduction right now: Compile zero-graphics by cloning it recursively and invoking a zig-git build build-wasm~~ Production is in comment below
Expected Behavior
The code should compile without any problem
Actual Behavior
LLVM Emit Object... LLVM ERROR: Unable to expand fixed point multiplication.
error: demo_application...
error: The following command terminated unexpectedly:
/home/felix/projects/forks/zig/build/zig2 build-lib /home/felix/projects/libraries/zero-graphics/src/main/wasm.zig -cflags -std=c99 -- /home/felix/projects/libraries/zero-graphics/src/rendering/stb_truetype.c --cache-dir /home/felix/projects/libraries/zero-graphics/zig-cache --global-cache-dir /home/felix/.cache/zig --name demo_application -dynamic -fsingle-threaded -target wasm32-freestanding-musl -mcpu generic --pkg-begin application /home/felix/projects/libraries/zero-graphics/examples/demo-application.zig --pkg-begin zero-graphics /home/felix/projects/libraries/zero-graphics/src/zero-graphics.zig --pkg-begin zigimg /home/felix/projects/libraries/zero-graphics/vendor/zigimg/zigimg.zig --pkg-end --pkg-begin ziglyph /home/felix/projects/libraries/zero-graphics/vendor/ziglyph/src/ziglyph.zig --pkg-end --pkg-begin zigstr /home/felix/projects/libraries/zero-graphics/vendor/zigstr/src/Zigstr.zig --pkg-begin ziglyph /home/felix/projects/libraries/zero-graphics/vendor/ziglyph/src/ziglyph.zig --pkg-end --pkg-end --pkg-begin TextEditor /home/felix/projects/libraries/zero-graphics/vendor/text-editor/src/TextEditor.zig --pkg-begin ziglyph /home/felix/projects/libraries/zero-graphics/vendor/ziglyph/src/ziglyph.zig --pkg-end --pkg-end --pkg-end --pkg-begin zlm /home/felix/projects/libraries/zero-graphics/vendor/zlm/zlm.zig --pkg-end --pkg-end --pkg-begin application-meta /home/felix/projects/libraries/zero-graphics/zig-cache/zero-graphics/o/37a97a273e465a12dc388ba9b37251725c277b2e/app-meta.zig --pkg-end --pkg-begin zigimg /home/felix/projects/libraries/zero-graphics/vendor/zigimg/zigimg.zig --pkg-end --pkg-begin ziglyph /home/felix/projects/libraries/zero-graphics/vendor/ziglyph/src/ziglyph.zig --pkg-end --pkg-begin zigstr /home/felix/projects/libraries/zero-graphics/vendor/zigstr/src/Zigstr.zig --pkg-begin ziglyph /home/felix/projects/libraries/zero-graphics/vendor/ziglyph/src/ziglyph.zig --pkg-end --pkg-end --pkg-begin TextEditor /home/felix/projects/libraries/zero-graphics/vendor/text-editor/src/TextEditor.zig --pkg-begin ziglyph /home/felix/projects/libraries/zero-graphics/vendor/ziglyph/src/ziglyph.zig --pkg-end --pkg-end -I /home/felix/projects/libraries/zero-graphics/vendor/stb -I /home/felix/projects/libraries/zero-graphics/src/scintilla --main-pkg-path /home/felix/projects/libraries/zero-graphics/src --enable-cache
After figuring out how llvm-reduce works, i have made a reduction:
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-unknown-musl"
define internal fastcc void @src.formats.png.reader.TrnsProcessor.processDataRow() {
Block28:
%0 = call i16 @llvm.umul.fix.sat.i16(i16 0, i16 1, i32 0)
store i16 %0, ptr null, align 1
ret void
}
; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
declare i16 @llvm.umul.fix.sat.i16(i16, i16, i32 immarg) #0
attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
Build it with zig build-lib -dynamic -target wasm32-freestanding-musl reduced.ll to reproduce the crash:
error(compilation): clang failed with stderr: fatal error: error in backend: Unable to expand fixed point multiplication.
zig: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 15.0.0 (https://github.com/llvm/llvm-project 6fe69891d15c69e2832e8158987f9d6179ce43bf)
Target: wasm32-unknown-unknown-musl
Thread model: posix
InstalledDir: /bin
zig: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
reduced.ll:1:1: error: unable to build C object: clang exited with code 1
So it seems like the problem originates from zigimg by using saturating arithmetics
Nice reduction! It should repro with vanilla clang/llc, based on that signature
Looks perfect for filing at https://github.com/llvm/llvm-project/issues/ if you want to take this upstream