authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-07 19:58:31+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 18:16:17-05:00
log2a5c622e65a07db95859beabf46f36d3a62c785a
tree401b1fd8c0796cadabadcc355840ccaf8150e62f
parent9f064bcf74ec0246630c0e5ed8df83df5c46aaaa

Fix crash with unresolved loc

Fixes #4099

2 files changed, 24 insertions(+), 7 deletions(-)

src/ir.cpp+7-7
......@@ -19278,7 +19278,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1927819278 return new_incoming_values.at(0);
1927919279 }
1928019280
19281 ZigType *resolved_type;
19281 ZigType *resolved_type = nullptr;
1928219282 if (peer_parent != nullptr) {
1928319283 bool peer_parent_has_type;
1928419284 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
......@@ -19288,23 +19288,23 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1928819288 resolved_type = ira->explicit_return_type;
1928919289 } else if (peer_parent->parent->id == ResultLocIdCast) {
1929019290 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
19291 if (type_is_invalid(resolved_type))
19292 return ira->codegen->invalid_instruction;
19293 } else {
19291 } else if (peer_parent->parent->resolved_loc) {
1929419292 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
1929519293 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
1929619294 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
1929719295 }
19298 goto skip_resolve_peer_types;
19296
19297 if (resolved_type != nullptr && type_is_invalid(resolved_type))
19298 return ira->codegen->invalid_instruction;
1929919299 }
1930019300 }
19301 {
19301
19302 if (resolved_type == nullptr) {
1930219303 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
1930319304 new_incoming_values.items, new_incoming_values.length);
1930419305 if (type_is_invalid(resolved_type))
1930519306 return ira->codegen->invalid_instruction;
1930619307 }
19307skip_resolve_peer_types:
1930819308
1930919309 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1931019310 case OnePossibleValueInvalid:
test/stage1/behavior/bitcast.zig+17
......@@ -150,3 +150,20 @@ test "comptime bitcast used in expression has the correct type" {
150150test "bitcast result to _" {
151151 _ = @bitCast(u8, @as(i8, 1));
152152}
153
154test "nested bitcast" {
155 const S = struct {
156 fn moo(x: isize) void {
157 @import("std").testing.expectEqual(@intCast(isize, 42), x);
158 }
159
160 fn foo(x: isize) void {
161 @This().moo(
162 @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)),
163 );
164 }
165 };
166
167 S.foo(42);
168 comptime S.foo(42);
169}