diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-08-31 13:45:42 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-31 13:45:42 +0200 |
commit | 2c8361bd39f98c869df7b23ee682c25a9929f64f (patch) | |
tree | 388cb124560c2af2e2b81e877a590f48cf2ee2f9 /tests/arithm | |
parent | b74faf354e3d998156ab73bbc7367e359c16de41 (diff) | |
download | Nim-2c8361bd39f98c869df7b23ee682c25a9929f64f.tar.gz |
Constant folding for integer casts (#8095)
Diffstat (limited to 'tests/arithm')
-rw-r--r-- | tests/arithm/tcast.nim | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/arithm/tcast.nim b/tests/arithm/tcast.nim new file mode 100644 index 000000000..954e2e677 --- /dev/null +++ b/tests/arithm/tcast.nim @@ -0,0 +1,60 @@ +discard """ + output: ''' +B0 +B1 +B2 +B3 +''' +""" + +template crossCheck(ty: untyped, exp: untyped) = + let rt = ty(exp) + const ct = ty(exp) + if $rt != $ct: + echo "Got ", ct + echo "Expected ", rt + +block: + when true: + echo "B0" + crossCheck(int8, 0'i16 - 5'i16) + crossCheck(int16, 0'i32 - 5'i32) + crossCheck(int32, 0'i64 - 5'i64) + + echo "B1" + crossCheck(uint8, 0'u8 - 5'u8) + crossCheck(uint16, 0'u16 - 5'u16) + crossCheck(uint32, 0'u32 - 5'u32) + crossCheck(uint64, 0'u64 - 5'u64) + + echo "B2" + crossCheck(uint8, uint8.high + 5'u8) + crossCheck(uint16, uint16.high + 5'u16) + crossCheck(uint32, uint32.high + 5'u32) + crossCheck(uint64, (-1).uint64 + 5'u64) + + echo "B3" + crossCheck(int8, 0'u8 - 5'u8) + crossCheck(int16, 0'u16 - 5'u16) + crossCheck(int32, 0'u32 - 5'u32) + crossCheck(int64, 0'u64 - 5'u64) + + # crossCheck(int8, 0'u16 - 129'u16) + # crossCheck(uint8, 0'i16 + 257'i16) + + # Signed integer {under,over}flow is guarded against + + # crossCheck(int8, int8.high + 5'i8) + # crossCheck(int16, int16.high + 5'i16) + # crossCheck(int32, int32.high + 5'i32) + # crossCheck(int64, int64.high + 5'i64) + + # crossCheck(int8, int8.low - 5'i8) + # crossCheck(int16, int16.low - 5'i16) + # crossCheck(int32, int32.low - 5'i32) + # crossCheck(int64, int64.low - 5'i64) + + # crossCheck(uint8, 0'i8 - 5'i8) + # crossCheck(uint16, 0'i16 - 5'i16) + # crossCheck(uint32, 0'i32 - 5'i32) + # crossCheck(uint64, 0'i64 - 5'i64) |