authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-08 15:34:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-08 15:34:41-04:00
log93840f8610974109d129e6940a851c1f7a8c9fce
tree27340e91d8a841dded09df37c762ebe8875495a7
parentcfe84423c97eb2121138c2de5876c47782cd6dda
signature Commit is signed but in an unrecognized format.

fix var args call on non-generic function


2 files changed, 64 insertions(+), 17 deletions(-)

src/ir.cpp+49-15
......@@ -15799,26 +15799,60 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1579915799 casted_args[next_arg_index] = casted_arg;
1580015800 next_arg_index += 1;
1580115801 }
15802 size_t iter_count = (call_param_count < call_instruction->arg_count) ?
15803 call_param_count : call_instruction->arg_count;
15804 for (size_t call_i = 0; call_i < iter_count; call_i += 1) {
15802 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
1580515803 IrInstruction *old_arg = call_instruction->args[call_i]->child;
1580615804 if (type_is_invalid(old_arg->value.type))
1580715805 return ira->codegen->invalid_instruction;
15808 IrInstruction *casted_arg;
15809 if (next_arg_index < src_param_count) {
15810 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
15811 if (type_is_invalid(param_type))
15812 return ira->codegen->invalid_instruction;
15813 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
15814 if (type_is_invalid(casted_arg->value.type))
15815 return ira->codegen->invalid_instruction;
15806
15807 if (old_arg->value.type->id == ZigTypeIdArgTuple) {
15808 for (size_t arg_tuple_i = old_arg->value.data.x_arg_tuple.start_index;
15809 arg_tuple_i < old_arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)
15810 {
15811 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
15812 if (arg_var == nullptr) {
15813 ir_add_error(ira, old_arg,
15814 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
15815 return ira->codegen->invalid_instruction;
15816 }
15817 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var);
15818 if (type_is_invalid(arg_var_ptr_inst->value.type))
15819 return ira->codegen->invalid_instruction;
15820
15821 IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr);
15822 if (type_is_invalid(arg_tuple_arg->value.type))
15823 return ira->codegen->invalid_instruction;
15824
15825 IrInstruction *casted_arg;
15826 if (next_arg_index < src_param_count) {
15827 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
15828 if (type_is_invalid(param_type))
15829 return ira->codegen->invalid_instruction;
15830 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type);
15831 if (type_is_invalid(casted_arg->value.type))
15832 return ira->codegen->invalid_instruction;
15833 } else {
15834 casted_arg = arg_tuple_arg;
15835 }
15836
15837 casted_args[next_arg_index] = casted_arg;
15838 next_arg_index += 1;
15839 }
1581615840 } else {
15817 casted_arg = old_arg;
15818 }
15841 IrInstruction *casted_arg;
15842 if (next_arg_index < src_param_count) {
15843 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
15844 if (type_is_invalid(param_type))
15845 return ira->codegen->invalid_instruction;
15846 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
15847 if (type_is_invalid(casted_arg->value.type))
15848 return ira->codegen->invalid_instruction;
15849 } else {
15850 casted_arg = old_arg;
15851 }
1581915852
15820 casted_args[next_arg_index] = casted_arg;
15821 next_arg_index += 1;
15853 casted_args[next_arg_index] = casted_arg;
15854 next_arg_index += 1;
15855 }
1582215856 }
1582315857
1582415858 assert(next_arg_index == call_param_count);
std/event/loop.zig+15-2
......@@ -1,5 +1,6 @@
11const std = @import("../std.zig");
22const builtin = @import("builtin");
3const root = @import("root");
34const assert = std.debug.assert;
45const testing = std.testing;
56const mem = std.mem;
......@@ -85,6 +86,18 @@ pub const Loop = struct {
8586 };
8687 };
8788
89 pub const IoMode = enum {
90 blocking,
91 evented,
92 };
93 pub const io_mode: IoMode = if (@hasDecl(root, "io_mode")) root.io_mode else IoMode.blocking;
94 var global_instance_state: Loop = undefined;
95 const default_instance: ?*Loop = switch (io_mode) {
96 .blocking => null,
97 .evented => &global_instance_state,
98 };
99 pub const instance: ?*Loop = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance;
100
88101 /// After initialization, call run().
89102 /// TODO copy elision / named return values so that the threads referencing *Loop
90103 /// have the correct pointer value.
......@@ -599,7 +612,7 @@ pub const Loop = struct {
599612 /// If the build is multi-threaded and there is an event loop, then it calls `yield`. Otherwise,
600613 /// does nothing.
601614 pub fn startCpuBoundOperation() void {
602 if (builtin.is_single_threaded) {
615 if (builtin.single_threaded) {
603616 return;
604617 } else if (instance) |event_loop| {
605618 event_loop.yield();
......@@ -881,7 +894,7 @@ test "std.event.Loop - call" {
881894
882895 var did_it = false;
883896 const handle = async Loop.call(testEventLoop);
884 const handle2 = async Loop.call(testEventLoop2, handle, &did_it);
897 const handle2 = async Loop.call(testEventLoop2, &handle, &did_it);
885898
886899 loop.run();
887900