| ... | ... | @@ -6413,9 +6413,9 @@ fn analyzeInlineCallArg( |
| 6413 | 6413 | }; |
| 6414 | 6414 | } |
| 6415 | 6415 | const casted_arg = try sema.coerce(arg_block, param_ty, uncasted_arg, arg_src); |
| 6416 | | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); |
| 6417 | 6416 | |
| 6418 | 6417 | if (is_comptime_call) { |
| 6418 | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); |
| 6419 | 6419 | const arg_val = sema.resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "argument to function being called at comptime must be comptime-known") catch |err| { |
| 6420 | 6420 | if (err == error.AnalysisFail and sema.err != null) { |
| 6421 | 6421 | try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty); |
| ... | ... | @@ -6440,6 +6440,20 @@ fn analyzeInlineCallArg( |
| 6440 | 6440 | .ty = param_ty, |
| 6441 | 6441 | .val = arg_val, |
| 6442 | 6442 | }; |
| 6443 | } else if ((try sema.resolveMaybeUndefVal(arg_block, arg_src, casted_arg) == null) or |
| 6444 | try sema.typeRequiresComptime(param_ty) or zir_tags[inst] == .param_comptime) |
| 6445 | { |
| 6446 | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); |
| 6447 | } else { |
| 6448 | // We have a comptime value but we need a runtime value to preserve inlining semantics, |
| 6449 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 6450 | .pointee_type = param_ty, |
| 6451 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), |
| 6452 | }); |
| 6453 | const alloc = try arg_block.addTy(.alloc, ptr_type); |
| 6454 | _ = try arg_block.addBinOp(.store, alloc, casted_arg); |
| 6455 | const loaded = try arg_block.addTyOp(.load, param_ty, alloc); |
| 6456 | try sema.inst_map.putNoClobber(sema.gpa, inst, loaded); |
| 6443 | 6457 | } |
| 6444 | 6458 | |
| 6445 | 6459 | arg_i.* += 1; |
| ... | ... | @@ -6448,9 +6462,10 @@ fn analyzeInlineCallArg( |
| 6448 | 6462 | // No coercion needed. |
| 6449 | 6463 | const uncasted_arg = uncasted_args[arg_i.*]; |
| 6450 | 6464 | new_fn_info.param_types[arg_i.*] = sema.typeOf(uncasted_arg); |
| 6451 | | try sema.inst_map.putNoClobber(sema.gpa, inst, uncasted_arg); |
| 6465 | const param_ty = sema.typeOf(uncasted_arg); |
| 6452 | 6466 | |
| 6453 | 6467 | if (is_comptime_call) { |
| 6468 | try sema.inst_map.putNoClobber(sema.gpa, inst, uncasted_arg); |
| 6454 | 6469 | const arg_val = sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to function being called at comptime must be comptime-known") catch |err| { |
| 6455 | 6470 | if (err == error.AnalysisFail and sema.err != null) { |
| 6456 | 6471 | try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty); |
| ... | ... | @@ -6475,6 +6490,20 @@ fn analyzeInlineCallArg( |
| 6475 | 6490 | .ty = sema.typeOf(uncasted_arg), |
| 6476 | 6491 | .val = arg_val, |
| 6477 | 6492 | }; |
| 6493 | } else if ((try sema.resolveMaybeUndefVal(arg_block, arg_src, uncasted_arg)) == null or |
| 6494 | try sema.typeRequiresComptime(param_ty) or zir_tags[inst] == .param_anytype_comptime) |
| 6495 | { |
| 6496 | try sema.inst_map.putNoClobber(sema.gpa, inst, uncasted_arg); |
| 6497 | } else { |
| 6498 | // We have a comptime value but we need a runtime value to preserve inlining semantics, |
| 6499 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 6500 | .pointee_type = param_ty, |
| 6501 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), |
| 6502 | }); |
| 6503 | const alloc = try arg_block.addTy(.alloc, ptr_type); |
| 6504 | _ = try arg_block.addBinOp(.store, alloc, uncasted_arg); |
| 6505 | const loaded = try arg_block.addTyOp(.load, param_ty, alloc); |
| 6506 | try sema.inst_map.putNoClobber(sema.gpa, inst, loaded); |
| 6478 | 6507 | } |
| 6479 | 6508 | |
| 6480 | 6509 | arg_i.* += 1; |