terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.72k stars 201 forks source link

macOS arm64 test failure: cconv_array.t #604

Closed shoe42 closed 2 years ago

shoe42 commented 2 years ago

The cconv_array.t test fails on macOS arm64 (M1). macOS 12.5, using system clang and Homebrew LLVM 13. Trimmed output:

$ ../build/bin/terra cconv_array.t
running test for int8[0]
running test for int8[1]
running test for int8[2]
running test for int8[3]
running test for int8[4]
running test for int8[5]
running test for int8[6]
running test for int8[7]
running test for int8[8]
running test for int8[9]
cconv_array.t:53: NYI: cannot call this C function (yet)
stack traceback:
    [C]: in function 'caller'
    cconv_array.t:53: in function 'run_test_case'
    cconv_array.t:64: in main chunk
elliottslaughter commented 2 years ago

I suspect this is a LuaJIT bug.

Can you please help me with this test?

bug604.c:

#include <stdint.h>

int8_t f(int8_t x0, int8_t x1, int8_t x2, int8_t x3, int8_t x4, int8_t x5, int8_t x6, int8_t x7, int8_t x8, int8_t x9) {
  return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9;
}

bug604.t:

local c = terralib.includecstring [[
#include <stdint.h>

int8_t f(int8_t x0, int8_t x1, int8_t x2, int8_t x3, int8_t x4, int8_t x5, int8_t x6, int8_t x7, int8_t x8, int8_t x9);
]]

terralib.linklibrary("libbug604.dylib")

print(c.f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

bug604.lua:

local ffi = require("ffi")

ffi.cdef [[
int8_t f(int8_t x0, int8_t x1, int8_t x2, int8_t x3, int8_t x4, int8_t x5, int8_t x6, int8_t x7, int8_t x8, int8_t x9);
]]

local c = ffi.load("libbug604")

print(c.f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

Then run:

clang bug604.c -o libbug604.dylib -shared -Wall
./build/bin/terra bug604.t
./build/bin/terra bug604.lua

It should print 45 with each of the last two commands, but I suspect it will fail with both.

shoe42 commented 2 years ago

Looks like it's still failing:

$ ../build/bin/terra bug604.t
bug604.t:9: NYI: cannot call this C function (yet)
stack traceback:
    [C]: in function 'f'
    bug604.t:9: in main chunk
$ ../build/bin/terra bug604.lua
bug604.lua:9: NYI: cannot call this C function (yet)
stack traceback:
    [C]: in function 'f'
    bug604.lua:9: in main chunk
elliottslaughter commented 2 years ago

Ok, definitely a LuaJIT bug. I'll file an issue shortly. It might help to have:

  1. uname -a
  2. XCode version (whether full XCode app or command line tools, output of clang --version)
  3. macOS version
shoe42 commented 2 years ago

Version info:

elliottslaughter commented 2 years ago

Upstream issue submitted: https://github.com/LuaJIT/LuaJIT/issues/888

elliottslaughter commented 2 years ago

The upstream issue was closed as a duplicate of https://github.com/LuaJIT/LuaJIT/issues/205, which has been open for six years with no indication of being a priority. I think at this point the best we can do is modify the bounds on this test so that we stick to what works.

elliottslaughter commented 2 years ago

@shoe42 Is this still failing? What does the output look like on master now?

shoe42 commented 2 years ago

Looks like on commit 71f2180cbf252f615c1fb7b2d7dd0746581b0741, the test fails with:

$ ../build/bin/terra cconv_array.t
running test for int8[0]
running test for int8[1]
running test for int8[2]
running test for int8[3]
running test for int8[4]
running test for int8[5]
running test for int8[6]
running test for int8[7]
running test for int8[8]
running test for int16[0]
running test for int16[1]
running test for int16[2]
running test for int16[3]
running test for int16[4]
running test for int16[5]
running test for int16[6]
running test for int16[7]
running test for int16[8]
running test for int16[9]
cconv_array.t:53: NYI: cannot call this C function (yet)
stack traceback:
    [C]: in function 'caller'
    cconv_array.t:53: in function 'run_test_case'
    cconv_array.t:74: in main chunk
elliottslaughter commented 2 years ago

Sigh. Ok, if you take out int16 for a moment, does it fail on int32 too? I can work around this but would like to know what types I'll need to do so for.

shoe42 commented 2 years ago

int32:

running test for int32[0]
running test for int32[1]
running test for int32[2]
running test for int32[3]
running test for int32[4]
running test for int32[5]
running test for int32[6]
running test for int32[7]
running test for int32[8]
running test for int32[9]
cconv_array.t:53: NYI: cannot call this C function (yet)
stack traceback:
    [C]: in function 'caller'
    cconv_array.t:53: in function 'run_test_case'
    cconv_array.t:74: in main chunk

float:

running test for float[0]
running test for float[1]
running test for float[2]
running test for float[3]
running test for float[4]
running test for float[5]
running test for float[6]
running test for float[7]
running test for float[8]
running test for float[9]
cconv_array.t:53: NYI: cannot call this C function (yet)
stack traceback:
    [C]: in function 'caller'
    cconv_array.t:53: in function 'run_test_case'
    cconv_array.t:74: in main chunk

int64 and double seem to all pass.

elliottslaughter commented 2 years ago

Thanks. I'll make a new workaround.

elliottslaughter commented 2 years ago

Can you try running the version of cconv_array.t in #611 and let me know if it works this time?

shoe42 commented 2 years ago

Yup, looks like that PR makes cconv_array.t pass tests now.

elliottslaughter commented 2 years ago

Thanks! Merged. I think all tests should pass in master now.

elliottslaughter commented 2 years ago

@shoe42 if you'd like to do one last check, I can get a release rolling.

shoe42 commented 2 years ago

Looks like everything is passing successfully - thanks for the work in bringing M1 test pass rate up to scratch!

elliottslaughter commented 2 years ago

Thanks, will release here shortly.

elliottslaughter commented 1 year ago

Just FYI: as of #642 I have pulled in an updated LuaJIT that fixes the root cause, and with that, we can now run the full cconv_array.t test again.