diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ddf9007fa..3c4a77b49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed + * Out-of-bounds literals are now an error rather than a warning. + ### Fixed * Fix bug in slice simplification (#992). diff --git a/examples/rosettacode/md5.fut b/examples/rosettacode/md5.fut index 5c3664629e..97a316c7ef 100644 --- a/examples/rosettacode/md5.fut +++ b/examples/rosettacode/md5.fut @@ -20,7 +20,6 @@ let rs: [64]u32 = 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 ] let ks: [64]u32 = - map us32 [ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee , 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501 , 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be , diff --git a/src/Language/Futhark/TypeChecker/Terms.hs b/src/Language/Futhark/TypeChecker/Terms.hs index 8af94d4422..8490a2ff71 100644 --- a/src/Language/Futhark/TypeChecker/Terms.hs +++ b/src/Language/Futhark/TypeChecker/Terms.hs @@ -2464,7 +2464,8 @@ literalOverflowCheck = void . check inBoundsF x Float32 = not $ isInfinite (realToFrac x :: Float) inBoundsF x Float64 = not $ isInfinite x warnBounds inBounds x ty loc = unless inBounds - $ warn loc $ "Literal " <> show x <> " out of bounds for inferred type " <> pretty ty <> "." + $ typeError loc mempty $ "Literal " <> ppr x <> + " out of bounds for inferred type " <> ppr ty <> "." -- | Type-check a top-level (or module-level) function definition. -- Despite the name, this is also used for checking constant diff --git a/tests/bitwise.fut b/tests/bitwise.fut index 11d21bcf49..03348232b5 100644 --- a/tests/bitwise.fut +++ b/tests/bitwise.fut @@ -4,32 +4,32 @@ -- Originally distilled from MD5 sum calculation. -- == -- input { --- 1732584193 --- -271733879 --- -1732584194 --- 271733878 +-- 1732584193u32 +-- -271733879u32 +-- -1732584194u32 +-- 271733878u32 -- 1 -- } -- output { --- 271733878 --- 757607282 --- -271733879 --- -1732584194 +-- 271733878u32 +-- 757607282u32 +-- -271733879u32 +-- -1732584194u32 -- } -let funF(x: i32, y: i32, z: i32): i32 = x & y | !x & z +let funF(x: u32, y: u32, z: u32): u32 = x & y | !x & z -let rotateL (x: i32, i: i32): i32 = +let rotateL (x: u32, i: u32): u32 = let post = x << i let pre = (x >> i) & (!(0xFFFFFFFF << i)) in post | pre -let frob(a: i32, b: i32, c: i32, d: i32): (i32, i32, i32, i32) = +let frob(a: u32, b: u32, c: u32, d: u32): (u32, u32, u32, u32) = let w = 0x97989910 let f' = funF(b,c,d) let a' = b + rotateL((a + f' + w + 0xd76aa478), 7) in (d, a', b, c) -let main (a: i32) (b: i32) (c: i32) (d: i32) (n: i32): (i32, i32, i32, i32) = - loop (a',b',c',d') = (a,b,c,d) for i < n do +let main (a: u32) (b: u32) (c: u32) (d: u32) (n: i32): (u32, u32, u32, u32) = + loop (a',b',c',d') = (a,b,c,d) for _i < n do frob(a',b',c',d') diff --git a/tests/overflowing_lits2.fut b/tests/overflowing/edgecases.fut similarity index 90% rename from tests/overflowing_lits2.fut rename to tests/overflowing/edgecases.fut index f0100bee75..becfb82933 100644 --- a/tests/overflowing_lits2.fut +++ b/tests/overflowing/edgecases.fut @@ -1,6 +1,5 @@ -- Some edge cases of literals that don't overflow, but are close -- -- == --- warning: ^$ entry main : (i8, i8, u16, f64) = (-128, 127, 65535, 1.79e308) diff --git a/tests/overflowing/f32high.fut b/tests/overflowing/f32high.fut new file mode 100644 index 0000000000..e8c851b59f --- /dev/null +++ b/tests/overflowing/f32high.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : f32 = 9.7e42 diff --git a/tests/overflowing/f32low.fut b/tests/overflowing/f32low.fut new file mode 100644 index 0000000000..897dab7997 --- /dev/null +++ b/tests/overflowing/f32low.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : f32 = -1e40 diff --git a/tests/overflowing/f64low.fut b/tests/overflowing/f64low.fut new file mode 100644 index 0000000000..db6c01b322 --- /dev/null +++ b/tests/overflowing/f64low.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : f64 = 1.8e308 diff --git a/tests/overflowing/i16low.fut b/tests/overflowing/i16low.fut new file mode 100644 index 0000000000..6c1c842718 --- /dev/null +++ b/tests/overflowing/i16low.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : i16 = -10000000 diff --git a/tests/overflowing/i32high.fut b/tests/overflowing/i32high.fut new file mode 100644 index 0000000000..667a154ab7 --- /dev/null +++ b/tests/overflowing/i32high.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : i32 = 1000000000000 diff --git a/tests/overflowing/i8high.fut b/tests/overflowing/i8high.fut new file mode 100644 index 0000000000..2c68594739 --- /dev/null +++ b/tests/overflowing/i8high.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : i8 = 128 diff --git a/tests/overflowing/i8low.fut b/tests/overflowing/i8low.fut new file mode 100644 index 0000000000..06401e2d4c --- /dev/null +++ b/tests/overflowing/i8low.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : i8 = -129 diff --git a/tests/overflowing/u16high.fut b/tests/overflowing/u16high.fut new file mode 100644 index 0000000000..424ba8d6eb --- /dev/null +++ b/tests/overflowing/u16high.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : u16 = 100000 diff --git a/tests/overflowing/u32low.fut b/tests/overflowing/u32low.fut new file mode 100644 index 0000000000..a9f5538025 --- /dev/null +++ b/tests/overflowing/u32low.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : u32 = -4 diff --git a/tests/overflowing/u8high.fut b/tests/overflowing/u8high.fut new file mode 100644 index 0000000000..a4fb7d68cc --- /dev/null +++ b/tests/overflowing/u8high.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : u8 = 256 diff --git a/tests/overflowing/u8low.fut b/tests/overflowing/u8low.fut new file mode 100644 index 0000000000..cef2e763e8 --- /dev/null +++ b/tests/overflowing/u8low.fut @@ -0,0 +1,4 @@ +-- == +-- error: (out of bounds.*) + +let main : u8 = -4 diff --git a/tests/overflowing_lits0.fut b/tests/overflowing_lits0.fut deleted file mode 100644 index cb2ed43ab1..0000000000 --- a/tests/overflowing_lits0.fut +++ /dev/null @@ -1,7 +0,0 @@ --- Warn on overflowing literals --- --- == --- warning: (out of bounds.*){5} - -entry main : (i16, i32, u16, u32, f32) - = (-10000000, 1000000000000, 100000, -4, 9.7e42) diff --git a/tests/overflowing_lits1.fut b/tests/overflowing_lits1.fut deleted file mode 100644 index 0cedbba6b9..0000000000 --- a/tests/overflowing_lits1.fut +++ /dev/null @@ -1,7 +0,0 @@ --- Warn on overflowing literals – edge cases that should produce warnings --- --- == --- warning: (out of bounds.*){6} - -entry main : (i8, i8, u8, u8, f32, f64) - = (-129, 128, -4, 256, -1e40, 1.8e308)