chung-leong / zigar

Enable the use of Zig code in JavaScript project
https://chung-leong.github.io/zigar/
MIT License
183 stars 3 forks source link

Variadic functions not working in MacOS on ARM 64 #421

Closed chung-leong closed 4 months ago

chung-leong commented 4 months ago

sprintf test results:

Mismatch: 0 != 1234
1/15 variadic.test.sprintf (i64)...SKIP

Mismatch: 0 1871616240 != 1234 4567
2/15 variadic.test.sprintf (i64, i32)...SKIP

Mismatch: 0 1871616112 0.000000 != 1234 4567 3.140000
3/15 variadic.test.sprintf (i64, i32, f64)...SKIP

Mismatch: (null), 6166583280 -2077872992 0.000000 != Hello world, 1234 4567 3.140000
4/15 variadic.test.sprintf (i64, i32, f64, [*:0]const u8)...SKIP

Mismatch: 7 8 9 10 11 12 13 14 15 16 1871613648 0 1871614240 -2077872992 1871616288 1871616440 != 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
5/15 variadic.test.sprintf (i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64)...SKIP

Mismatch: 0.000000 != 1.230000
6/15 variadic.test.sprintf (f64)...SKIP

Mismatch: Hello 0.000000 0.000000!! != Hello 1.234000 4.234000!!
7/15 variadic.test.sprintf (f64, f64)...SKIP

Mismatch: 0 0.000000 != 123 1.230000
8/15 variadic.test.sprintf (i32, f64)...SKIP

Mismatch: 0 1871616144 0.000000 != 123 456 1.230000
9/15 variadic.test.sprintf (i32, i32, f64)...SKIP

Mismatch: 9.000000 10.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 != 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000 10.000000
10/15 variadic.test.sprintf (f64, f64, f64, f64, f64, f64, f64, f64, f64, f64)...SKIP

Mismatch: 9.000000 10.000000 11.000000 12.000000 13.000000 14.000000 15.000000 16.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 != 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000 10.000000 11.000000 12.000000 13.000000 14.000000 15.000000 16.000000
11/15 variadic.test.sprintf (f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64)...SKIP

Mismatch: 0 0.000000 != -123 3.140000
12/15 variadic.test.sprintf (i64, f64)...SKIP

Mismatch: 0 0.000000 6512061600 0.000000 != -123 3.140000 -235 7.770000
13/15 variadic.test.sprintf (i64, f64, i64, f64)...SKIP

Mismatch: 0 -26336 != -123 -124
14/15 variadic.test.sprintf (i16, i16)...SKIP

Mismatch: 0 32 != -123 -124
15/15 variadic.test.sprintf (i8, i8)...SKIP
0 passed; 15 skipped; 0 failed.
chung-leong commented 4 months ago

Getting a different error now:

install
+- WriteFile
   +- zig build-lib call-variadic-functions ReleaseSmall aarch64-macos failure
error: LLVM ERROR: Cannot select: 0x126b15fa0: f128 = fp_round 0x126b16010, TargetConstant:i64<1>
  0x126b16010: f64,ch = load<(load (s64))> 0x126a4a600, 0x126b16470, undef:i64
    0x126b16470: i64 = and 0x126a4a440, Constant:i64<-16>
      0x126a4a440: i64 = add 0x126bd60a0, Constant:i64<15>
        0x126bd60a0: i64,ch = load<(load (s64) from %ir.23)> 0x10f15eca0, FrameIndex:i64<20>, undef:i64
          0x126bd5e70: i64 = FrameIndex<20>
          0x126a4a210: i64 = undef
        0x126bd6880: i64 = Constant<15>
      0x126b16240: i64 = Constant<-16>
    0x126a4a210: i64 = undef
  0x126a4bfe0: i64 = TargetConstant<1>
In function: call-variadic-functions.printFloats

error: the following command terminated unexpectedly:
/Users/m1/.zvm/0.13.0/zig build-lib -OReleaseSmall -target aarch64-macos -mcpu baseline --dep module -Mroot=/Users/m1/zigar/zigar-compiler/zig/stub-c.zig -I /Users/m1/zigar/zigar-compiler/test/integration/function-calling -Mmodule=/Users/m1/zigar/zigar-compiler/test/integration/function-calling/call-variadic-functions.zig -lc --cache-dir /private/var/folders/3j/qqxfy2j50pxcwr66ndvvsxz80000gn/T/zigar-build/call-variadic-fu-23afc1a4/.zig-cache --global-cache-dir /Users/m1/.cache/zig --name call-variadic-functions -dynamic -install_name @rpath/libcall-variadic-functions.dylib --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
+- WriteFile transitive failure
   +- zig build-lib call-variadic-functions ReleaseSmall aarch64-macos failure
   +- zig build-lib call-variadic-functions ReleaseSmall aarch64-macos (reused)
error: the following build command failed with exit code 1:
/private/var/folders/3j/qqxfy2j50pxcwr66ndvvsxz80000gn/T/zigar-build/call-variadic-fu-23afc1a4/.zig-cache/o/96020fe8c8d178383619b5cf80b74557/build /Users/m1/.zvm/0.13.0/zig /private/var/folders/3j/qqxfy2j50pxcwr66ndvvsxz80000gn/T/zigar-build/call-variadic-fu-23afc1a4 /private/var/folders/3j/qqxfy2j50pxcwr66ndvvsxz80000gn/T/zigar-build/call-variadic-fu-23afc1a4/.zig-cache /Users/m1/.cache/zig --seed 0x9bd46527 -Z55be7135d09dcbcb -Doptimize=ReleaseSmall -Dtarget=aarch64-macos
chung-leong commented 4 months ago

Test case is failing with f16, f32, and f80. This might be due to MacOS expecting the caller to sign extend instead of the callee.

Code just won't compile if f128 is used. LLVM error from @cVarArg().

chung-leong commented 4 months ago

At least printf() is working now. Some types are still problematic. Not sure if it's due to the compiler or our code. Revisit the issue after issues related to LLVM are fixed.