authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-12 18:27:34-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-12 18:27:34-05:00
log0931b85bd04fb671dce980728a3692de2bd496a5
tree685a16034c2908fb9f6437d546db40c9f09ecf65
parent79ec5a02875bb4af0dbcc186ffc03e693938db9a

fix crash when return value is ??void

closes #258

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

src/ir.cpp+16-1
...@@ -9985,8 +9985,23 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -9985,8 +9985,23 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
9985 if (value->value.type->id == TypeTableEntryIdInvalid)9985 if (value->value.type->id == TypeTableEntryIdInvalid)
9986 return ira->codegen->builtin_types.entry_invalid;9986 return ira->codegen->builtin_types.entry_invalid;
99879987
9988 // This will be a pointer type because test null IR instruction operates on a pointer to a thing.
9989 TypeTableEntry *ptr_type = value->value.type;9988 TypeTableEntry *ptr_type = value->value.type;
9989 if (ptr_type->id == TypeTableEntryIdMetaType) {
9990 // surprise! actually this is just ??T not an unwrap maybe instruction
9991 TypeTableEntry *ptr_type_ptr = ir_resolve_type(ira, value);
9992 assert(ptr_type_ptr->id == TypeTableEntryIdPointer);
9993 TypeTableEntry *child_type = ptr_type_ptr->data.pointer.child_type;
9994 type_ensure_zero_bits_known(ira->codegen, child_type);
9995 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
9996 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);
9997 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, layer2, true);
9998
9999 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
10000 unwrap_maybe_instruction->base.source_node, result_type);
10001 ir_link_new_instruction(const_instr, &unwrap_maybe_instruction->base);
10002 return const_instr->value.type;
10003 }
10004
9990 assert(ptr_type->id == TypeTableEntryIdPointer);10005 assert(ptr_type->id == TypeTableEntryIdPointer);
999110006
9992 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;10007 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
test/run_tests.cpp+5
...@@ -1622,6 +1622,11 @@ fn bar(a: i32, b: []const u8) {...@@ -1622,6 +1622,11 @@ fn bar(a: i32, b: []const u8) {
1622 ".tmp_source.zig:8:5: error: found compile log statement",1622 ".tmp_source.zig:8:5: error: found compile log statement",
1623 ".tmp_source.zig:3:17: note: called from here");1623 ".tmp_source.zig:3:17: note: called from here");
16241624
1625 add_compile_fail_case("double ?? on main return value", R"SOURCE(
1626pub fn main(args: [][]u8) -> ??void {
1627}
1628 )SOURCE", 1, ".tmp_source.zig:2:30: error: expected return type of main to be '%void', instead is '??void'");
1629
1625}1630}
16261631
1627//////////////////////////////////////////////////////////////////////////////1632//////////////////////////////////////////////////////////////////////////////