@@ -10463,13 +10463,6 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
1046310463 zig_unreachable();
1046410464}
1046510465
10466- static IrInstruction *ir_implicit_byval_const_ref_cast(IrAnalyze *ira, IrInstruction *inst) {
10467- if (type_is_copyable(ira->codegen, inst->value.type))
10468- return inst;
10469- TypeTableEntry *const_ref_type = get_pointer_to_type(ira->codegen, inst->value.type, true);
10470- return ir_implicit_cast(ira, inst, const_ref_type);
10471- }
10472-
1047310466static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
1047410467 TypeTableEntry *type_entry = ptr->value.type;
1047510468 if (type_is_invalid(type_entry)) {
@@ -12283,7 +12276,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1228312276 IrInstruction *casted_arg;
1228412277 if (is_var_args) {
1228512278 arg_part_of_generic_id = true;
12286- casted_arg = ir_implicit_byval_const_ref_cast(ira, arg) ;
12279+ casted_arg = arg;
1228712280 } else {
1228812281 if (param_decl_node->data.param_decl.var_token == nullptr) {
1228912282 AstNode *param_type_node = param_decl_node->data.param_decl.type;
@@ -12296,7 +12289,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1229612289 return false;
1229712290 } else {
1229812291 arg_part_of_generic_id = true;
12299- casted_arg = ir_implicit_byval_const_ref_cast(ira, arg) ;
12292+ casted_arg = arg;
1230012293 }
1230112294 }
1230212295
@@ -12515,9 +12508,18 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1251512508
1251612509 size_t next_proto_i = 0;
1251712510 if (first_arg_ptr) {
12518- IrInstruction *first_arg;
1251912511 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
12520- if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
12512+
12513+ bool first_arg_known_bare = false;
12514+ if (fn_type_id->next_param_index >= 1) {
12515+ TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
12516+ if (type_is_invalid(param_type))
12517+ return ira->codegen->builtin_types.entry_invalid;
12518+ first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
12519+ }
12520+
12521+ IrInstruction *first_arg;
12522+ if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
1252112523 first_arg = first_arg_ptr;
1252212524 } else {
1252312525 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
@@ -12667,9 +12669,18 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1266712669 size_t next_proto_i = 0;
1266812670
1266912671 if (first_arg_ptr) {
12670- IrInstruction *first_arg;
1267112672 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
12672- if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
12673+
12674+ bool first_arg_known_bare = false;
12675+ if (fn_type_id->next_param_index >= 1) {
12676+ TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
12677+ if (type_is_invalid(param_type))
12678+ return ira->codegen->builtin_types.entry_invalid;
12679+ first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
12680+ }
12681+
12682+ IrInstruction *first_arg;
12683+ if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
1267312684 first_arg = first_arg_ptr;
1267412685 } else {
1267512686 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
@@ -12802,10 +12813,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1280212813 return ira->codegen->builtin_types.entry_invalid;
1280312814 }
1280412815 if (inst_fn_type_id.async_allocator_type == nullptr) {
12805- IrInstruction *casted_inst = ir_implicit_byval_const_ref_cast(ira, uncasted_async_allocator_inst);
12806- if (type_is_invalid(casted_inst->value.type))
12807- return ira->codegen->builtin_types.entry_invalid;
12808- inst_fn_type_id.async_allocator_type = casted_inst->value.type;
12816+ inst_fn_type_id.async_allocator_type = uncasted_async_allocator_inst->value.type;
1280912817 }
1281012818 async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, inst_fn_type_id.async_allocator_type);
1281112819 if (type_is_invalid(async_allocator_inst->value.type))
@@ -12866,20 +12874,23 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1286612874 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
1286712875 size_t next_arg_index = 0;
1286812876 if (first_arg_ptr) {
12869- IrInstruction *first_arg;
1287012877 assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
12871- if (handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) {
12878+
12879+ TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
12880+ if (type_is_invalid(param_type))
12881+ return ira->codegen->builtin_types.entry_invalid;
12882+
12883+ IrInstruction *first_arg;
12884+ if (param_type->id == TypeTableEntryIdPointer &&
12885+ handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))
12886+ {
1287212887 first_arg = first_arg_ptr;
1287312888 } else {
1287412889 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
1287512890 if (type_is_invalid(first_arg->value.type))
1287612891 return ira->codegen->builtin_types.entry_invalid;
1287712892 }
1287812893
12879- TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
12880- if (type_is_invalid(param_type))
12881- return ira->codegen->builtin_types.entry_invalid;
12882-
1288312894 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
1288412895 if (type_is_invalid(casted_arg->value.type))
1288512896 return ira->codegen->builtin_types.entry_invalid;
0 commit comments