@floatToInt now has safety-checked undefined behavior

when the integer part does not fit in the destination integer type

 * Also fix incorrect safety triggered for integer casting an
   `i32` to a `u7`. closes #1138
 * adds compiler-rt function: `__floatuntidf`
This commit is contained in:
Andrew Kelley
2018-06-19 16:06:10 -04:00
parent 0b92d689d0
commit c7804277bf
12 changed files with 291 additions and 9 deletions

View File

@@ -1,6 +1,23 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@floatToInt comptime safety",
\\comptime {
\\ _ = @floatToInt(i8, f32(-129.1));
\\}
\\comptime {
\\ _ = @floatToInt(u8, f32(-1.1));
\\}
\\comptime {
\\ _ = @floatToInt(u8, f32(256.1));
\\}
,
".tmp_source.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
".tmp_source.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'",
".tmp_source.zig:8:9: error: integer value '256' cannot be stored in type 'u8'",
);
cases.add(
"use c_void as return type of fn ptr",
\\export fn entry() void {