authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-21 23:24:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-21 23:25:02-05:00
logad0871ea4bf2dfbed07282ffe14738b5347d5d32
tree17497337d26c37cf2bbc7d68d2813c22fea5c661
parent94299d16d1443cd8b731e2eba9b4d1e3fb8048bd
parent4e6c1b676b30920fb333a6aa270bb42dc4cecc79
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'Vexu-missing-cast'

Closes #3336 Closes #3718

5 files changed, 34 insertions(+), 13 deletions(-)

lib/std/child_process.zig+1-1
...@@ -63,7 +63,7 @@ pub const ChildProcess = struct {...@@ -63,7 +63,7 @@ pub const ChildProcess = struct {
6363
64 /// Windows-only. `cwd` was provided, but the path did not exist when spawning the child process.64 /// Windows-only. `cwd` was provided, but the path did not exist when spawning the child process.
65 CurrentWorkingDirectoryUnlinked,65 CurrentWorkingDirectoryUnlinked,
66 } || os.ExecveError || os.SetIdError || os.ChangeCurDirError || windows.CreateProcessError;66 } || os.ExecveError || os.SetIdError || os.ChangeCurDirError || windows.CreateProcessError || windows.WaitForSingleObjectError;
6767
68 pub const Term = union(enum) {68 pub const Term = union(enum) {
69 Exited: u32,69 Exited: u32,
lib/std/coff.zig+1-1
...@@ -179,7 +179,7 @@ pub const Coff = struct {...@@ -179,7 +179,7 @@ pub const Coff = struct {
179 if (byte != 0 and i == buffer.len)179 if (byte != 0 and i == buffer.len)
180 return error.NameTooLong;180 return error.NameTooLong;
181181
182 return i;182 return @as(usize, i);
183 }183 }
184184
185 pub fn loadSections(self: *Coff) !void {185 pub fn loadSections(self: *Coff) !void {
src/codegen.cpp+1-1
...@@ -7725,7 +7725,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7725,7 +7725,7 @@ static void do_code_gen(CodeGen *g) {
77257725
7726 char *error = nullptr;7726 char *error = nullptr;
7727 if (LLVMVerifyModule(g->module, LLVMReturnStatusAction, &error)) {7727 if (LLVMVerifyModule(g->module, LLVMReturnStatusAction, &error)) {
7728 zig_panic("broken LLVM module found: %s", error);7728 zig_panic("broken LLVM module found: %s\nThis is a bug in the Zig compiler.", error);
7729 }7729 }
7730}7730}
77317731
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 {