|
| 1 | +--[[ |
| 2 | +SPDX-License-Identifier: ISC |
| 3 | +Copyright (c) 2023-2025, Sergey Bronnikov. |
| 4 | +
|
| 5 | +ARM64: Should not fuse sign-extension into logical operands, |
| 6 | +can fuse rotations though, |
| 7 | +https://github.com/LuaJIT/LuaJIT/issues/1076 |
| 8 | +
|
| 9 | +Wrong code generation for constants in bitwise operations, |
| 10 | +https://github.com/lua/lua/commit/c764ca71a639f5585b5f466bea25dc42b855a4b0 |
| 11 | +
|
| 12 | +Synopsis: bit.bor(x1 [,x2...]) |
| 13 | +]] |
| 14 | + |
| 15 | +local luzer = require("luzer") |
| 16 | +local test_lib = require("lib") |
| 17 | + |
| 18 | +local unpack = unpack or table.unpack |
| 19 | + |
| 20 | +local bor |
| 21 | +if test_lib.lua_version() == "LuaJIT" then |
| 22 | + bor = bit.bor |
| 23 | +else |
| 24 | + bor = test_lib.bitwise_op("|") |
| 25 | +end |
| 26 | + |
| 27 | +local function TestOneInput(buf) |
| 28 | + local fdp = luzer.FuzzedDataProvider(buf) |
| 29 | + local MAX_INT = test_lib.MAX_INT |
| 30 | + local MIN_INT = test_lib.MIN_INT |
| 31 | + local x = fdp:consume_integer(MIN_INT, MAX_INT) |
| 32 | + local y = fdp:consume_integer(MIN_INT, MAX_INT) |
| 33 | + local z = fdp:consume_integer(MIN_INT, MAX_INT) |
| 34 | + local res = bor(x, y) |
| 35 | + assert(type(res) == "number") |
| 36 | + |
| 37 | + assert(bor(x, y) == bor(y, x)) |
| 38 | + assert(bor(x, bor(y, z)) == bor(bor(x, y), z)) |
| 39 | + assert(bor(x, 0) == x) |
| 40 | + assert(bor(x, x) == x) |
| 41 | + if test_lib.lua_version() == "LuaJIT" then |
| 42 | + local MAX_UINT = bor(test_lib.MAX_INT, test_lib.MIN_INT) |
| 43 | + assert(bor(x, MAX_UINT) == MAX_UINT) |
| 44 | + else |
| 45 | + local MAX_UINT64 = bor(test_lib.MAX_INT64, test_lib.MIN_INT64) |
| 46 | + assert(bor(x, MAX_UINT64) == MAX_UINT64) |
| 47 | + end |
| 48 | + |
| 49 | + -- Multiple arguments. |
| 50 | + -- `n` must be less than UINT_MAX and there are at least extra |
| 51 | + -- free stack slots in the stack, otherwise an error |
| 52 | + -- "too many results to unpack" is raised, see <ltablib.c>. |
| 53 | + local n = fdp:consume_integer(2, 1024) |
| 54 | + local args = fdp:consume_integers(0, MAX_INT, n) |
| 55 | + res = bor(unpack(args)) |
| 56 | + assert(type(res) == "number") |
| 57 | +end |
| 58 | + |
| 59 | +local args = { |
| 60 | + artifact_prefix = "bitop_bor_", |
| 61 | +} |
| 62 | +luzer.Fuzz(TestOneInput, nil, args) |
0 commit comments