authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-02-12 20:27:08+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-13 16:18:24-05:00
loga090a5e3bcf242e8ed69346d9762d9c2fab6059a
tree614ef55bc7ed3f39dcfcae82931c606e158d9e75
parente8dfc5e7f615c0c8a529623560d6adc3dc029c1b

ir: Don't crash when converting undefined ptrs


1 files changed, 9 insertions(+), 2 deletions(-)

src/ir.cpp+9-2
......@@ -267,6 +267,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
267267static ResultLoc *no_result_loc(void);
268268static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
269269static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
270static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty);
270271
271272static void destroy_instruction_src(IrInstSrc *inst) {
272273 switch (inst->id) {
......@@ -12784,13 +12785,19 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI
1278412785 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));
1278512786
1278612787 if (instr_is_comptime(value)) {
12787 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
12788 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
12789 if (val == nullptr)
12790 return ira->codegen->invalid_inst_gen;
12791 if (val->special == ConstValSpecialUndef)
12792 return ir_const_undef(ira, source_instr, wanted_type);
12793
12794 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
1278812795 if (pointee == nullptr)
1278912796 return ira->codegen->invalid_inst_gen;
1279012797 if (pointee->special != ConstValSpecialRuntime) {
1279112798 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1279212799 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
12793 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
12800 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
1279412801 result->value->data.x_ptr.data.base_array.array_val = pointee;
1279512802 result->value->data.x_ptr.data.base_array.elem_index = 0;
1279612803 return result;