summaryrefslogtreecommitdiff
path: root/testes/bitwise.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-23 11:08:10 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-23 11:08:10 -0300
commit26be27459b11feabed52cf40aaa76f86c7edc977 (patch)
tree9f3cd8be898991a52f6b5f8b140a12b8b9acb51d /testes/bitwise.lua
parentcfbe378f906061ee56f91acfbdf569d0d3fb9556 (diff)
downloadlua-github-26be27459b11feabed52cf40aaa76f86c7edc977.tar.gz
Negation in constant folding of '>>' may overflow
Diffstat (limited to 'testes/bitwise.lua')
-rw-r--r--testes/bitwise.lua12
1 files changed, 12 insertions, 0 deletions
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