| ... | ... | @@ -4491,17 +4491,29 @@ pub const FuncGen = struct { |
| 4491 | 4491 | } |
| 4492 | 4492 | return null; |
| 4493 | 4493 | } |
| 4494 | |
| 4494 | 4495 | const abi_ret_ty = try lowerFnRetTy(self.dg, fn_info); |
| 4496 | const ptr_abi_ty = abi_ret_ty.pointerType(0); |
| 4495 | 4497 | const operand = try self.resolveInst(un_op); |
| 4498 | const target = self.dg.module.getTarget(); |
| 4499 | const alignment = ret_ty.abiAlignment(target); |
| 4500 | |
| 4501 | if (isByRef(ret_ty)) { |
| 4502 | // operand is a pointer however self.ret_ptr is null so that means |
| 4503 | // we need to return a value. |
| 4504 | const casted_ptr = self.builder.buildBitCast(operand, ptr_abi_ty, ""); |
| 4505 | const load_inst = self.builder.buildLoad(casted_ptr, ""); |
| 4506 | load_inst.setAlignment(alignment); |
| 4507 | _ = self.builder.buildRet(load_inst); |
| 4508 | return null; |
| 4509 | } |
| 4510 | |
| 4496 | 4511 | const llvm_ret_ty = operand.typeOf(); |
| 4497 | 4512 | if (abi_ret_ty == llvm_ret_ty) { |
| 4498 | 4513 | _ = self.builder.buildRet(operand); |
| 4499 | 4514 | return null; |
| 4500 | 4515 | } |
| 4501 | 4516 | |
| 4502 | | const target = self.dg.module.getTarget(); |
| 4503 | | const alignment = ret_ty.abiAlignment(target); |
| 4504 | | const ptr_abi_ty = abi_ret_ty.pointerType(0); |
| 4505 | 4517 | const rp = self.buildAlloca(llvm_ret_ty); |
| 4506 | 4518 | rp.setAlignment(alignment); |
| 4507 | 4519 | const store_inst = self.builder.buildStore(operand, rp); |