forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFI: Add missing coercion when recording 64-bit bit.*().
Thanks to Peter Cawley. (cherry picked from commit 304da39) Before the patch, with the missed coercion from string, there is the cast to `i64` from `p64`, where the last one is the string address. This leads to an incorrect result of the bit operation. This patch adds the missing coercion everywhere for bit operations recording. Only the `recff_bit64_nary()` is affected, since all other routines have the corresponding type check and cast emitting if necessary. However, for the consistency, all functions have the same checking routine `crec_bit64_arg()` now. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#10709 Reviewed-by: Sergey Bronnikov <[email protected]> Signed-off-by: Sergey Kaplun <[email protected]> (cherry picked from commit c698ff5)
- Loading branch information
Showing
3 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/tarantool-tests/lj-1252-missing-bit64-coercion.test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
local tap = require('tap') | ||
|
||
-- Test file to demonstrate LuaJIT incorrect recording of | ||
-- `bit` library with needed coercion from string. | ||
-- See also: https://github.com/LuaJIT/LuaJIT/issues/1252. | ||
|
||
local test = tap.test('lj-1252-missing-bit64-coercion'):skipcond({ | ||
['Test requires JIT enabled'] = not jit.status(), | ||
}) | ||
|
||
test:plan(1) | ||
|
||
-- Simplify the `jit.dump()` output. | ||
local bor = bit.bor | ||
|
||
jit.opt.start('hotloop=1') | ||
|
||
-- Before the patch, with the missed coercion from string, there | ||
-- is the cast to `i64` from `p64`, where the last one is the | ||
-- string address. This leads to an incorrect result of the bit | ||
-- operation. | ||
|
||
local results = {} | ||
for i = 1, 4 do | ||
results[i] = bor('0', 0LL) | ||
end | ||
|
||
test:samevalues(results, 'correct recording of the bit operation with coercion') | ||
|
||
test:done(true) |