From 26be27459b11feabed52cf40aaa76f86c7edc977 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 23 Sep 2022 11:08:10 -0300 Subject: Negation in constant folding of '>>' may overflow --- testes/bitwise.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'testes') diff --git a/testes/bitwise.lua b/testes/bitwise.lua index 9509f7f0..dd0a1a9a 100644 --- a/testes/bitwise.lua +++ b/testes/bitwise.lua @@ -38,6 +38,18 @@ d = d << 32 assert(a | b ~ c & d == 0xF4000000 << 32) assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) + +do -- constant folding + local code = string.format("return -1 >> %d", math.maxinteger) + assert(load(code)() == 0) + local code = string.format("return -1 >> %d", math.mininteger) + assert(load(code)() == 0) + local code = string.format("return -1 << %d", math.maxinteger) + assert(load(code)() == 0) + local code = string.format("return -1 << %d", math.mininteger) + assert(load(code)() == 0) +end + assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000) assert(-1 >> (numbits - 1) == 1) assert(-1 >> numbits == 0 and -- cgit v1.2.3-55-g6feb