diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-09-23 11:08:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-09-23 11:08:10 -0300 |
commit | 26be27459b11feabed52cf40aaa76f86c7edc977 (patch) | |
tree | 9f3cd8be898991a52f6b5f8b140a12b8b9acb51d /testes/bitwise.lua | |
parent | cfbe378f906061ee56f91acfbdf569d0d3fb9556 (diff) | |
download | lua-26be27459b11feabed52cf40aaa76f86c7edc977.tar.gz lua-26be27459b11feabed52cf40aaa76f86c7edc977.tar.bz2 lua-26be27459b11feabed52cf40aaa76f86c7edc977.zip |
Negation in constant folding of '>>' may overflow
Diffstat (limited to 'testes/bitwise.lua')
-rw-r--r-- | testes/bitwise.lua | 12 |
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 | |||
38 | assert(a | b ~ c & d == 0xF4000000 << 32) | 38 | assert(a | b ~ c & d == 0xF4000000 << 32) |
39 | assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) | 39 | assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) |
40 | 40 | ||
41 | |||
42 | do -- constant folding | ||
43 | local code = string.format("return -1 >> %d", math.maxinteger) | ||
44 | assert(load(code)() == 0) | ||
45 | local code = string.format("return -1 >> %d", math.mininteger) | ||
46 | assert(load(code)() == 0) | ||
47 | local code = string.format("return -1 << %d", math.maxinteger) | ||
48 | assert(load(code)() == 0) | ||
49 | local code = string.format("return -1 << %d", math.mininteger) | ||
50 | assert(load(code)() == 0) | ||
51 | end | ||
52 | |||
41 | assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000) | 53 | assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000) |
42 | assert(-1 >> (numbits - 1) == 1) | 54 | assert(-1 >> (numbits - 1) == 1) |
43 | assert(-1 >> numbits == 0 and | 55 | assert(-1 >> numbits == 0 and |