authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-18 10:22:15+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-18 10:22:15+03:00
log78962eeeda07d613ebdfd239082268a6702c19db
treeecd9d8f2503b69cd49cce34edf5e827c68ba5767
parent39915ae08668884f51071feb4b1132b1903f0abb
signaturelock-open Commit is signed but in an unrecognized format.

fix floatCast type check regression

Closes #5900

2 files changed, 18 insertions(+), 0 deletions(-)

src/ir.cpp+6
...@@ -26739,6 +26739,12 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo...@@ -26739,6 +26739,12 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
26739 }26739 }
26740 }26740 }
2674126741
26742 if (target->value->type->id != ZigTypeIdFloat) {
26743 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",
26744 buf_ptr(&target->value->type->name)));
26745 return ira->codegen->invalid_inst_gen;
26746 }
26747
26742 if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeFloat) {26748 if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeFloat) {
26743 ZigValue *val = ir_resolve_const(ira, target, UndefBad);26749 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
26744 if (val == nullptr)26750 if (val == nullptr)
test/compile_errors.zig+12
...@@ -122,6 +122,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -122,6 +122,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
122 \\ var a: u32 = 2;122 \\ var a: u32 = 2;
123 \\ _ = @floatToInt(u32, a);123 \\ _ = @floatToInt(u32, a);
124 \\}124 \\}
125 \\export fn qux() void {
126 \\ var a: f32 = 2;
127 \\ _ = @intCast(u32, a);
128 \\}
125 , &[_][]const u8{129 , &[_][]const u8{
126 "tmp.zig:3:32: error: unable to evaluate constant expression",130 "tmp.zig:3:32: error: unable to evaluate constant expression",
127 "tmp.zig:3:9: note: referenced here",131 "tmp.zig:3:9: note: referenced here",
...@@ -129,6 +133,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -129,6 +133,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
129 "tmp.zig:7:9: note: referenced here",133 "tmp.zig:7:9: note: referenced here",
130 "tmp.zig:11:26: error: expected float type, found 'u32'",134 "tmp.zig:11:26: error: expected float type, found 'u32'",
131 "tmp.zig:11:9: note: referenced here",135 "tmp.zig:11:9: note: referenced here",
136 "tmp.zig:15:23: error: expected integer type, found 'f32'",
137 "tmp.zig:15:9: note: referenced here",
132 });138 });
133139
134 cases.addTest("invalid float casts",140 cases.addTest("invalid float casts",
...@@ -144,6 +150,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -144,6 +150,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
144 \\ var a: f32 = 2;150 \\ var a: f32 = 2;
145 \\ _ = @intToFloat(f32, a);151 \\ _ = @intToFloat(f32, a);
146 \\}152 \\}
153 \\export fn qux() void {
154 \\ var a: u32 = 2;
155 \\ _ = @floatCast(f32, a);
156 \\}
147 , &[_][]const u8{157 , &[_][]const u8{
148 "tmp.zig:3:36: error: unable to evaluate constant expression",158 "tmp.zig:3:36: error: unable to evaluate constant expression",
149 "tmp.zig:3:9: note: referenced here",159 "tmp.zig:3:9: note: referenced here",
...@@ -151,6 +161,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -151,6 +161,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
151 "tmp.zig:7:9: note: referenced here",161 "tmp.zig:7:9: note: referenced here",
152 "tmp.zig:11:26: error: expected int type, found 'f32'",162 "tmp.zig:11:26: error: expected int type, found 'f32'",
153 "tmp.zig:11:9: note: referenced here",163 "tmp.zig:11:9: note: referenced here",
164 "tmp.zig:15:25: error: expected float type, found 'u32'",
165 "tmp.zig:15:9: note: referenced here",
154 });166 });
155167
156 cases.addTest("invalid assignments",168 cases.addTest("invalid assignments",