authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-19 17:29:43+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-21 23:21:51-05:00
log4d9318cee075fbc662cb4e20a74c7f887c3a3da4
tree6699e141ca4ee19b2c59fce4524256e34a86d557
parent0b63573674c76bd45f641774c16e0d4e96ee74fd
signaturelock-open Commit is signed but in an unrecognized format.

fix missing implicit cast in return instruction


2 files changed, 31 insertions(+), 10 deletions(-)

src/ir.cpp+10-10
...@@ -13535,16 +13535,6 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -13535,16 +13535,6 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
13535 if (type_is_invalid(operand->value.type))13535 if (type_is_invalid(operand->value.type))
13536 return ir_unreach_error(ira);13536 return ir_unreach_error(ira);
1353713537
13538 if (!instr_is_comptime(operand) && ira->explicit_return_type != nullptr &&
13539 handle_is_ptr(ira->explicit_return_type))
13540 {
13541 // result location mechanism took care of it.
13542 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
13543 instruction->base.source_node, nullptr);
13544 result->value.type = ira->codegen->builtin_types.entry_unreachable;
13545 return ir_finish_anal(ira, result);
13546 }
13547
13548 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);13538 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
13549 if (type_is_invalid(casted_operand->value.type)) {13539 if (type_is_invalid(casted_operand->value.type)) {
13550 AstNode *source_node = ira->explicit_return_type_source_node;13540 AstNode *source_node = ira->explicit_return_type_source_node;
...@@ -13556,6 +13546,16 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -13556,6 +13546,16 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
13556 return ir_unreach_error(ira);13546 return ir_unreach_error(ira);
13557 }13547 }
1355813548
13549 if (!instr_is_comptime(operand) && ira->explicit_return_type != nullptr &&
13550 handle_is_ptr(ira->explicit_return_type))
13551 {
13552 // result location mechanism took care of it.
13553 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
13554 instruction->base.source_node, nullptr);
13555 result->value.type = ira->codegen->builtin_types.entry_unreachable;
13556 return ir_finish_anal(ira, result);
13557 }
13558
13559 if (casted_operand->value.special == ConstValSpecialRuntime &&13559 if (casted_operand->value.special == ConstValSpecialRuntime &&
13560 casted_operand->value.type->id == ZigTypeIdPointer &&13560 casted_operand->value.type->id == ZigTypeIdPointer &&
13561 casted_operand->value.data.rh_ptr == RuntimeHintPtrStack)13561 casted_operand->value.data.rh_ptr == RuntimeHintPtrStack)
test/compile_errors.zig+21
...@@ -12,6 +12,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -12,6 +12,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12 "tmp.zig:3:5: error: switch must handle all possibilities",12 "tmp.zig:3:5: error: switch must handle all possibilities",
13 );13 );
1414
15 cases.add(
16 "incorrect return type",
17 \\ pub export fn entry() void{
18 \\ _ = foo();
19 \\ }
20 \\ const A = struct {
21 \\ a: u32,
22 \\ };
23 \\ fn foo() A {
24 \\ return bar();
25 \\ }
26 \\ const B = struct {
27 \\ a: u32,
28 \\ };
29 \\ fn bar() B {
30 \\ unreachable;
31 \\ }
32 ,
33 "tmp.zig:8:16: error: expected type 'A', found 'B'",
34 );
35
15 cases.add(36 cases.add(
16 "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",37 "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
17 \\const Foo = struct {38 \\const Foo = struct {