From a82c499a0d3a000c1776a2723649fb6d241f0528 Mon Sep 17 00:00:00 2001 From: Peter Cawley Date: Sun, 24 Apr 2016 00:03:58 +0100 Subject: [PATCH] Modernise some FFI tests. --- test/lib/ffi/{ffi_bit64.lua => bit64.lua} | 48 ++++++++------ .../ffi/{ffi_copy_fill.lua => copy_fill.lua} | 6 +- test/lib/ffi/ffi_redir.lua | 22 ------- test/lib/ffi/index | 7 ++ .../ffi/{ffi_jit_array.lua => jit_array.lua} | 58 ++++++++--------- .../{ffi_jit_struct.lua => jit_struct.lua} | 64 +++++++++---------- ...fi_meta_tostring.lua => meta_tostring.lua} | 27 ++++---- test/lib/ffi/redir.lua | 19 ++++++ ...{ffi_type_punning.lua => type_punning.lua} | 33 ++++------ test/lib/index | 2 +- .../ffi/ffi_sink.lua => opt/sink/ffi.lua} | 31 +++++---- test/{lib/ffi => opt/sink}/ffi_nosink.lua | 12 ++-- test/opt/sink/index | 2 + 13 files changed, 169 insertions(+), 162 deletions(-) rename test/lib/ffi/{ffi_bit64.lua => bit64.lua} (76%) rename test/lib/ffi/{ffi_copy_fill.lua => copy_fill.lua} (96%) delete mode 100644 test/lib/ffi/ffi_redir.lua create mode 100644 test/lib/ffi/index rename test/lib/ffi/{ffi_jit_array.lua => jit_array.lua} (70%) rename test/lib/ffi/{ffi_jit_struct.lua => jit_struct.lua} (69%) rename test/lib/ffi/{ffi_meta_tostring.lua => meta_tostring.lua} (69%) create mode 100644 test/lib/ffi/redir.lua rename test/lib/ffi/{ffi_type_punning.lua => type_punning.lua} (75%) rename test/{lib/ffi/ffi_sink.lua => opt/sink/ffi.lua} (79%) rename test/{lib/ffi => opt/sink}/ffi_nosink.lua (79%) diff --git a/test/lib/ffi/ffi_bit64.lua b/test/lib/ffi/bit64.lua similarity index 76% rename from test/lib/ffi/ffi_bit64.lua rename to test/lib/ffi/bit64.lua index 46cf60143c..d1b47bef7b 100644 --- a/test/lib/ffi/ffi_bit64.lua +++ b/test/lib/ffi/bit64.lua @@ -11,27 +11,37 @@ typedef enum { ZZI = -1 } ienum_t; typedef enum { ZZU } uenum_t; ]] -assert(tobit(0xfedcba9876543210ll) == 0x76543210) -assert(tobit(0xfedcba9876543210ull) == 0x76543210) +do --- smoke tobit + assert(tobit(0xfedcba9876543210ll) == 0x76543210) + assert(tobit(0xfedcba9876543210ull) == 0x76543210) +end -assert(tostring(band(1ll, 1, 1ll, -1)) == "1LL") -assert(tostring(band(1ll, 1, 1ull, -1)) == "1ULL") +do --- smoke band + assert(tostring(band(1ll, 1, 1ll, -1)) == "1LL") + assert(tostring(band(1ll, 1, 1ull, -1)) == "1ULL") +end -assert(shl(10ll, 2) == 40) -assert(shl(10, 2ll) == 40) -assert(shl(10ll, 2ll) == 40) +do --- smoke shl + assert(shl(10ll, 2) == 40) + assert(shl(10, 2ll) == 40) + assert(shl(10ll, 2ll) == 40) +end -assert(bit.tohex(0x123456789abcdef0LL) == "123456789abcdef0") +do --- smoke tohex + assert(bit.tohex(0x123456789abcdef0LL) == "123456789abcdef0") +end -for _,tp in ipairs{ "int", "ienum_t", "uenum_t", "int64_t", "uint64_t"} do - local x = ffi.new(tp, 10) - local y = tobit(x) - local z = band(x) - assert(type(y) == "number" and y == 10) - assert(type(z) == "cdata" and z == 10) +do --- tobit/band assorted C types + for _,tp in ipairs{"int", "ienum_t", "uenum_t", "int64_t", "uint64_t"} do + local x = ffi.new(tp, 10) + local y = tobit(x) + local z = band(x) + assert(type(y) == "number" and y == 10) + assert(type(z) == "cdata" and z == 10) + end end -do +do --- tobit/band negative unsigned enum local x = ffi.new("uenum_t", -10) local y = tobit(x) local z = band(x) @@ -41,7 +51,7 @@ do assert(z == 2^32-10) end -do +do --- jit band/bor/bxor local a = 0x123456789abcdef0LL local y1, y2, y3, y4, y5, y6 for i=1,100 do @@ -88,7 +98,7 @@ do assert(y6 == 0x123456786543210fLL) end -do +do --- jit shift/xor local a, b = 0x123456789abcdef0LL, 0x31415926535898LL for i=1,200 do a = bxor(a, b); b = sar(b, 14) + shl(b, 50) @@ -98,7 +108,7 @@ do assert(b == -7993764627526027113LL) end -do +do --- jit rotate/xor local a, b = 0x123456789abcdef0LL, 0x31415926535898LL for i=1,200 do a = bxor(a, b); b = rol(b, 14) @@ -108,7 +118,7 @@ do assert(b == -6199148037344061526LL) end -do +do --- jit all ops local a, b = 0x123456789abcdef0LL, 0x31415926535898LL for i=1,200 do a = bxor(a, b); b = rol(b, a) diff --git a/test/lib/ffi/ffi_copy_fill.lua b/test/lib/ffi/copy_fill.lua similarity index 96% rename from test/lib/ffi/ffi_copy_fill.lua rename to test/lib/ffi/copy_fill.lua index ef060bad05..295638182d 100644 --- a/test/lib/ffi/ffi_copy_fill.lua +++ b/test/lib/ffi/copy_fill.lua @@ -1,6 +1,6 @@ local ffi = require("ffi") -do +do --- misc local arr = ffi.typeof("char[11]") local a = arr() local b = arr() @@ -43,14 +43,14 @@ do assert(ffi.string(c, 5) == "AAAAA") end -do +do --- jit char[10] local a = ffi.new("char[10]", 64) local x for i=1,100 do a[0] = i; x = ffi.string(a, 10) end assert(x == "d@@@@@@@@@") end -do +do --- jit char[1] local a = ffi.new("char[1]") local x, y for i=1,100 do diff --git a/test/lib/ffi/ffi_redir.lua b/test/lib/ffi/ffi_redir.lua deleted file mode 100644 index 72e6e307bc..0000000000 --- a/test/lib/ffi/ffi_redir.lua +++ /dev/null @@ -1,22 +0,0 @@ -local ffi = require("ffi") - -ffi.cdef[[ -int foo(const char *s) asm("strlen"); -]] - -assert(ffi.C.foo("abcd") == 4) - -if ffi.abi("win") then - ffi.cdef[[ - int bar asm("_fmode"); - ]] -else - ffi.cdef[[ - int bar asm("errno"); - ]] -end - -ffi.C.bar = 14 -assert(ffi.C.bar == 14) -ffi.C.bar = 0 - diff --git a/test/lib/ffi/index b/test/lib/ffi/index new file mode 100644 index 0000000000..0ccd1ab531 --- /dev/null +++ b/test/lib/ffi/index @@ -0,0 +1,7 @@ +bit64.lua +bit +copy_fill.lua +jit_array.lua +jit_struct.lua +meta_tostring.lua +redir.lua +type_punning.lua diff --git a/test/lib/ffi/ffi_jit_array.lua b/test/lib/ffi/jit_array.lua similarity index 70% rename from test/lib/ffi/ffi_jit_array.lua rename to test/lib/ffi/jit_array.lua index 13e26dbe33..e8de4af13c 100644 --- a/test/lib/ffi/ffi_jit_array.lua +++ b/test/lib/ffi/jit_array.lua @@ -1,28 +1,29 @@ local ffi = require("ffi") -local types = { - "int8_t", "uint8_t", - "int16_t", "uint16_t", - "int32_t", "uint32_t", - "int64_t", "uint64_t", - "float", "double", -} - -for j,tp in ipairs(types) do - local t = ffi.new(tp.."[?]", 301) - for i=1,300 do t[i] = 1 end - for i=1,300 do assert(t[i] == 1) end - for i=1,300 do t[i] = t[i-1] end -- reassoc across PHIs, a[i-1] forwarding - for i=1,300 do assert(t[i] == 0) end - for i=1,300 do t[i] = i end - local x = 0 - for i=1,300 do x = x + t[i] end - if tp == "int8_t" then assert(x == 862) - elseif tp == "uint8_t" then assert(x == 33630) - else assert(x == 45150) end +do --- smoke + local types = { + "int8_t", "uint8_t", + "int16_t", "uint16_t", + "int32_t", "uint32_t", + "int64_t", "uint64_t", + "float", "double", + } + for j,tp in ipairs(types) do + local t = ffi.new(tp.."[?]", 301) + for i=1,300 do t[i] = 1 end + for i=1,300 do assert(t[i] == 1) end + for i=1,300 do t[i] = t[i-1] end -- reassoc across PHIs, a[i-1] forwarding + for i=1,300 do assert(t[i] == 0) end + for i=1,300 do t[i] = i end + local x = 0 + for i=1,300 do x = x + t[i] end + if tp == "int8_t" then assert(x == 862) + elseif tp == "uint8_t" then assert(x == 33630) + else assert(x == 45150) end + end end -do +do --- int array pointer arithmetic local a = ffi.new("int[?]", 101) local p = a+1; for i=1,100 do @@ -35,7 +36,7 @@ do for i=1,100 do assert((i+a)[0] == i) end -- pointer arithmetic end -do +do --- double array pointer arithmetic local a = ffi.new("double[?]", 101) local p = a+1; for i=1,100 do @@ -46,7 +47,7 @@ do for i=1,100 do assert((a+i)[0] == i) end -- pointer arithmetic end -do +do --- double array pointer comparisons +bit local a = ffi.new("double[?]", 201) local p = a+3 for i=1,200 do local j = bit.band(i, 7); assert((a+j == p) == (j == 3)) end @@ -55,13 +56,13 @@ do for i=1,200 do assert((a+i <= p) == (i <= 100)) end end -do +do --- constant offset in double array index local a = ffi.new("double[?]", 100) for i=1,100 do a[i-1LL] = i end for i=1,100 do assert(a[100LL-i] == 101-i) end end -do +do --- fixed index of minus one local a = ffi.new("int[10]") local p = a+1 local k = ffi.new("int", -1) @@ -69,14 +70,14 @@ do for i=1,100 do assert(p[-1] == 42); assert(p[k] == 42) end end -do +do --- uint8_t array element comparisons local a = ffi.new("uint8_t[?]", 256) for i=0,255 do a[i] = i end for i=1,255 do assert(a[i] >= 1) end for i=0,254 do assert(a[i] <= 254) end end -do +do --- int32_t array bit/bswap tricks +bit local a = ffi.new("int32_t[?]", 256) local tobit, bswap, shl = bit.tobit, bit.bswap, bit.lshift for i=0,255 do a[i] = bswap(i+0x12345600) end @@ -84,7 +85,7 @@ do for i=0,255 do assert(bswap(a[i]) == tobit(i+0x12345600)) end end -do +do --- int32_t shift/rotate/and +bit local a = ffi.new("int32_t[?]", 256) local shl, shr, rol, band = bit.lshift, bit.rshift, bit.rol, bit.band for i=0,255 do a[i] = i + shl(i, 8) + shl(i, 16) end @@ -101,4 +102,3 @@ do for i=0,255 do assert(shl(band(a[i], 0x000000ff), 24) == shl(i, 24)) end for i=0,255 do assert(shr(band(a[i], 0xffff0000), 16) == i) end end - diff --git a/test/lib/ffi/ffi_jit_struct.lua b/test/lib/ffi/jit_struct.lua similarity index 69% rename from test/lib/ffi/ffi_jit_struct.lua rename to test/lib/ffi/jit_struct.lua index e42743c90c..8aa64c1bca 100644 --- a/test/lib/ffi/ffi_jit_struct.lua +++ b/test/lib/ffi/jit_struct.lua @@ -1,17 +1,17 @@ local ffi = require("ffi") ffi.cdef[[ -typedef struct { int a, b, c; } foo_t; -typedef struct { int a, b, c; } foo2_t; -typedef struct { int a[10]; int b[10]; } sarr_t; -typedef struct chain_t { - struct chain_t *next; +typedef struct { int a, b, c; } jit_struct_foo_t; +typedef struct { int a, b, c; } jit_struct_foo2_t; +typedef struct { int a[10]; int b[10]; } jit_struct_sarr_t; +typedef struct jit_struct_chain_t { + struct jit_struct_chain_t *next; int v; -} chain_t; +} jit_struct_chain_t; ]] -do - local s = ffi.new("foo_t") +do --- iteration variable as field name + local s = ffi.new("jit_struct_foo_t") for j,k in ipairs{ "a", "b", "c" } do for i=1,100 do s[k] = s[k] + j end end @@ -20,8 +20,8 @@ do assert(s.c == 300) end -do - local s = ffi.new("foo_t") +do --- constant field names + local s = ffi.new("jit_struct_foo_t") for i=1,100 do s.a = s.a + 1 s.b = s.b + 2 @@ -32,9 +32,9 @@ do assert(s.c == 300) end -do - local s = ffi.new("foo_t") - local s2 = ffi.new("foo2_t", 1, 2, 3) +do --- constants from structure + local s = ffi.new("jit_struct_foo_t") + local s2 = ffi.new("jit_struct_foo2_t", 1, 2, 3) for i=1,100 do s.a = s.a + s2.a s.b = s.b + s2.b @@ -45,8 +45,8 @@ do assert(s.c == 300) end -do - local s = ffi.new("sarr_t") +do --- adding to array elements + local s = ffi.new("jit_struct_sarr_t") for i=1,100 do s.a[5] = s.a[5] + 1 s.b[5] = s.b[5] + 2 @@ -55,7 +55,7 @@ do assert(s.b[5] == 200) end -do +do --- double indexing local s = ffi.new([[ struct { struct { @@ -72,7 +72,7 @@ do assert(x == 105) end -do +do --- structurally identical local s1 = ffi.new("struct { int a; }") local s2 = ffi.new("struct { int a; }") local x = 0 @@ -92,7 +92,7 @@ do end end -do +do --- structurally different local s1 = ffi.new("struct { int a; }") local s2 = ffi.new("struct { char a; }") local x = 0 @@ -112,7 +112,7 @@ do end end -do +do --- union local s = ffi.new("union { uint8_t a; int8_t b; }") local x = 0 for i=1,200 do @@ -122,10 +122,10 @@ do assert(x == 1412) end -do - local s1 = ffi.new("chain_t") - local s2 = ffi.new("chain_t") - local s3 = ffi.new("chain_t") +do --- circular chain + local s1 = ffi.new("jit_struct_chain_t") + local s2 = ffi.new("jit_struct_chain_t") + local s3 = ffi.new("jit_struct_chain_t") s1.next = s2 s2.next = s3 s3.next = s1 @@ -139,7 +139,7 @@ do assert(s3.v == 99) end -do +do --- int struct initialiser local ct = ffi.typeof("struct { int a,b,c; }") local x,y,z = 0,0,0 for i=1,100 do @@ -153,7 +153,7 @@ do assert(z == 0) end -do +do --- double struct initialiser local ct = ffi.typeof("struct { double a,b,c; }") local x,y,z = 0,0,0 for i=1,100 do @@ -167,28 +167,28 @@ do assert(z == 0) end -do - local s1 = ffi.new("chain_t") +do --- pointer / int struct initialiser + local s1 = ffi.new("jit_struct_chain_t") local s for i=1,100 do - s = ffi.new("chain_t", s1, i) + s = ffi.new("jit_struct_chain_t", s1, i) end assert(tonumber(ffi.cast("int", s.next)) == - tonumber(ffi.cast("int", ffi.cast("chain_t *", s1)))) + tonumber(ffi.cast("int", ffi.cast("jit_struct_chain_t *", s1)))) assert(s.v == 100) end -do +do --- unstable pointer/int type struct initialiser local ct = ffi.typeof("struct { int *p; int y; }") local s for i=1,200 do - if i == 100 then ct = ffi.typeof("chain_t") end + if i == 100 then ct = ffi.typeof("jit_struct_chain_t") end s = ct(nil, 10) end assert(s.v == 10) end -do +do --- upvalued int box local s = ffi.new("struct { int x; }", 42) local function f() for i=1,100 do diff --git a/test/lib/ffi/ffi_meta_tostring.lua b/test/lib/ffi/meta_tostring.lua similarity index 69% rename from test/lib/ffi/ffi_meta_tostring.lua rename to test/lib/ffi/meta_tostring.lua index 57a34fca9d..bb065e16ab 100644 --- a/test/lib/ffi/ffi_meta_tostring.lua +++ b/test/lib/ffi/meta_tostring.lua @@ -1,31 +1,32 @@ local ffi = require("ffi") ffi.cdef[[ -typedef union foo_t { +typedef union meta_tostring_foo_t { int64_t i64; uint64_t u64; complex cd; double d[2]; complex float cf; float f[2]; -} foo_t; +} meta_tostring_foo_t; ]] -do - local foo_t = ffi.typeof("foo_t") - local x = foo_t() - local s - - assert(tostring(foo_t) == "ctype") - assert(string.match(tostring(x), "^cdata: ")) - +do --- tostring/typeof semi-roundtrip assert(tostring(ffi.typeof("int (*(*[1][2])[3][4])[5][6]")) == - "ctype") + "ctype") assert(tostring(ffi.typeof("int (*const)(void)")) == - "ctype") + "ctype") assert(tostring(ffi.typeof("complex float(*(void))[2]")) == - "ctype") + "ctype") assert(tostring(ffi.typeof("complex*")) == "ctype") +end + +do --- assorted union fields + local foo_t = ffi.typeof("meta_tostring_foo_t") + local x = foo_t() + + assert(tostring(foo_t) == "ctype") + assert(string.find(tostring(x), "^cdata: ")) x.i64 = -1; assert(tostring(x.i64) == "-1LL") diff --git a/test/lib/ffi/redir.lua b/test/lib/ffi/redir.lua new file mode 100644 index 0000000000..c492055adc --- /dev/null +++ b/test/lib/ffi/redir.lua @@ -0,0 +1,19 @@ +local ffi = require("ffi") + +do --- function + ffi.cdef[[ + int redir_foo(const char *s) asm("strlen"); + ]] + + assert(ffi.C.redir_foo("abcd") == 4) +end + +do --- variable -windows + ffi.cdef[[ + int redir_bar asm("errno"); + ]] + + ffi.C.redir_bar = 14 + assert(ffi.C.redir_bar == 14) + ffi.C.redir_bar = 0 +end diff --git a/test/lib/ffi/ffi_type_punning.lua b/test/lib/ffi/type_punning.lua similarity index 75% rename from test/lib/ffi/ffi_type_punning.lua rename to test/lib/ffi/type_punning.lua index b889b52f25..ac70b4b4cb 100644 --- a/test/lib/ffi/ffi_type_punning.lua +++ b/test/lib/ffi/type_punning.lua @@ -16,8 +16,7 @@ union { } ]]) --- float -> u32 type punning at same offset -do +do --- float -> u32 type punning at same offset local x = 0LL for i=1,100 do u.f[0] = i @@ -26,8 +25,7 @@ do assert(x == 110888222720LL) end --- double -> u64 type punning at same offset -do +do --- double -> u64 type punning at same offset local x = 0LL for i=1,100 do u.d[0] = i @@ -36,8 +34,7 @@ do assert(x == 1886586031403171840ULL) end --- i8 -> u8 type punning at same offset (fwd -> CONV.int.u8) -do +do --- i8 -> u8 type punning at same offset (fwd -> CONV.int.u8) local x = 0 for i=-100,100 do u.i8[0] = i @@ -46,8 +43,7 @@ do assert(x == 25600) end --- p32/p64 -> u64 type punning at same offset (32 bit: different size) -do +do --- p32/p64 -> u64 type punning at same offset (32 bit: different size) local x = 0LL u.u64[0] = 0 for i=-100,150 do @@ -58,8 +54,7 @@ do (ffi.abi"le" and 0x6400001883ULL or 0x188300000000ULL))) end --- u16 -> u8 type punning at overlapping offsets -do +do --- u16 -> u8 type punning at overlapping offsets [0] local x = 0 for i=255,520 do u.u16[0] = i @@ -68,7 +63,7 @@ do assert(x == (ffi.abi"be" and 274 or 32931)) end -do +do --- u16 -> u8 type punning at overlapping offsets [1] local x = 0 for i=255,520 do u.u16[0] = i @@ -77,8 +72,7 @@ do assert(x == (ffi.abi"le" and 274 or 32931)) end --- i16 -> i32 type punning at overlapping offsets -do +do --- i16 -> i32 type punning at overlapping offsets [0] local x = 0 u.i32[0] = 0 for i=-100,150 do @@ -88,7 +82,7 @@ do assert(x == (ffi.abi"be" and 411238400 or 6559875)) end -do +do --- i16 -> i32 type punning at overlapping offsets [1] local x = 0 u.i32[0] = 0 for i=-100,150 do @@ -98,8 +92,7 @@ do assert(x == (ffi.abi"le" and 411238400 or 6559875)) end --- double -> i32 type punning at overlapping offsets -do +do --- double -> i32 type punning at overlapping offsets [0] local x = 0 for i=1.5,120,1.1 do u.d[0] = i @@ -108,7 +101,7 @@ do assert(x == (ffi.abi"be" and 116468870297 or -858993573)) end -do +do --- double -> i32 type punning at overlapping offsets [1] local x = 0 for i=1.5,120,1.1 do u.d[0] = i @@ -117,8 +110,7 @@ do assert(x == (ffi.abi"le" and 116468870297 or -858993573)) end --- u32 -> u64 type punning, constify u, 32 bit SPLIT: fold KPTR -do +do --- u32 -> u64 type punning, constify u, 32 bit SPLIT: fold KPTR local u = ffi.new("union { struct { uint32_t lo, hi; }; uint64_t u64; }") local function conv(lo, hi) @@ -134,8 +126,7 @@ do assert(x == 21689584849850ULL) end --- u64 -> u32 -> u64 type punning with KPTR -do +do --- u64 -> u32 -> u64 type punning with KPTR local s = ffi.new("union { int64_t q; int32_t i[2]; }") local function f() s.q = 0 diff --git a/test/lib/index b/test/lib/index index b22eaf883c..cc9d7d7301 100644 --- a/test/lib/index +++ b/test/lib/index @@ -4,5 +4,5 @@ math string table coroutine - +ffi +ffi contents.lua \ No newline at end of file diff --git a/test/lib/ffi/ffi_sink.lua b/test/opt/sink/ffi.lua similarity index 79% rename from test/lib/ffi/ffi_sink.lua rename to test/opt/sink/ffi.lua index ea65912764..0bba0978d2 100644 --- a/test/lib/ffi/ffi_sink.lua +++ b/test/opt/sink/ffi.lua @@ -1,12 +1,12 @@ local ffi = require("ffi") -do +do --- incrementing local x = 10000000000000ll for i=1,100 do x=x+1 end assert(x == 10000000000100ll) end -do +do --- hoistable increment !private_G local x = 10000000000000ll local z for i=1,100 do z=x+1 end @@ -16,25 +16,25 @@ do assert(g == 10000000000000ll) end -do +do --- escaping hoistable increment local x = 10000000000000ll for i=1,100 do local y=x+1; if i == 90 then x=y end end assert(x == 10000000000001ll) end -do +do --- escaping addition local x = 10000000000000ll for i=1,100 do local y=x+i; if i == 90 then x=y end end assert(x == 10000000000090ll) end -do +do --- conditional addition / incrementing local x = 10000000000000ll for i=1,200 do local y=x+i; if i > 100 then x=y end end assert(x == 10000000015050ll) end -do +do --- incrementing pointer local a = ffi.new("int[?]", 100) local p = a for i=0,99 do p[0]=i; p=p+1 end @@ -42,7 +42,7 @@ do for i=0,99 do assert(a[i] == i) end end -do +do --- mutating complex local cx = ffi.typeof("complex") local x = cx(1, 2) local k = cx(3, 4) @@ -51,7 +51,7 @@ do assert(x.im == 402) end -do +do --- mutating struct local st = ffi.typeof("struct { int a; int64_t b; double c; }") local x = st(1, 20000000000LL, 3.5) local k = st(3, 4, 5.0) @@ -86,7 +86,7 @@ do assert(z.c == 200) end -do +do --- mutating struct 2 local st = ffi.typeof("struct { int64_t a; double b; float c; }") local x = st(1, 2.5, 3.25) local k = st(3, 4, 5) @@ -96,7 +96,7 @@ do assert(x.c == 503.25) end -do +do --- escaping loop counter to float local st = ffi.typeof("struct { float a; }") local x for i=1,200 do @@ -106,17 +106,16 @@ do assert(x.a == 200) end -do +do --- 64 bit crash bug !private_G local t = {} for i=1,200 do t[i] = "abcd" end local r for i=1,200 do local a,b,c,d - local g = t[201-i] -- Non-zero stack slot above. - local v = ffi.cast("const char *", t[i]) -- Uses 32 bit stack slot! - a,b,c,d = {v[0]},{v[1]},{v[2]},{v[3]} -- Force above to spill. - r = {{i}} -- Spill due to call. + local g = t[201-i] -- Non-zero stack slot above. + local v = ffi.cast("const char *", t[i]) -- Uses 32 bit stack slot! + a,b,c,d = {v[0]},{v[1]},{v[2]},{v[3]} -- Force above to spill. + r = {{i}} -- Spill due to call. if i > 100 then z = v[0]+a[1]+b[1]+c[1]+d[1] end -- Crash for 64 bit ptr v. end end - diff --git a/test/lib/ffi/ffi_nosink.lua b/test/opt/sink/ffi_nosink.lua similarity index 79% rename from test/lib/ffi/ffi_nosink.lua rename to test/opt/sink/ffi_nosink.lua index ae51dde1a1..8f7cced264 100644 --- a/test/lib/ffi/ffi_nosink.lua +++ b/test/opt/sink/ffi_nosink.lua @@ -1,20 +1,20 @@ local ffi = require("ffi") -do +do --- escaping global !private_G local x = 0ll for i=1,100 do x=x+1; g=x end assert(x == 100ll) assert(g == 100ll) end -do +do --- preincrement escaping global !private_G local x = 0ll for i=1,100 do local y=x; x=x+1; g=y end assert(x == 100ll) assert(g == 99ll) end -do +do --- escaping global and local !private_G local x = 0ll local z for i=1,100 do z=x+1; g=z end @@ -22,21 +22,21 @@ do assert(g == 1ll) end -do +do --- swapping local x,y = 0ll, 0ll for i=1,100 do y,x=x,x+1 end assert(x == 100ll) assert(y == 99ll) end -do +do --- pointer to self local st = ffi.typeof("struct { void *p; }") local x for i=1,100 do x = st(); x.p = x end assert(x.p == ffi.cast("void *", x)) end -do +do --- strchr ffi.cdef[[char *strchr(char *, int);]] for i=1,100 do local p = ffi.new("char[2]"); diff --git a/test/opt/sink/index b/test/opt/sink/index index 137f46ab31..8bfa370e50 100644 --- a/test/opt/sink/index +++ b/test/opt/sink/index @@ -1,2 +1,4 @@ alloc.lua nosink.lua +ffi.lua +ffi +ffi_nosink.lua +ffi