authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 00:15:03+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 20:25:12+02:00
log08a00f0d1ce477c2c57072b9b0e27eb36a73092a
tree95fa6b00950afd6c288c07e9c3eea508756f2dd7
parent835a1f7f0cfb6fdefdb7a6a3d3a6e04eafeb96d0

llvm: use alignment of ABI return type when it differs from raw return type

This would previously cause miscompilations when the ABI type had bigger alignment than the raw type.

2 files changed, 1 insertions(+), 3 deletions(-)

src/codegen/llvm.zig+1-1
...@@ -4876,7 +4876,7 @@ pub const FuncGen = struct {...@@ -4876,7 +4876,7 @@ pub const FuncGen = struct {
4876 // In this case the function return type is honoring the calling convention by having4876 // In this case the function return type is honoring the calling convention by having
4877 // a different LLVM type than the usual one. We solve this here at the callsite4877 // a different LLVM type than the usual one. We solve this here at the callsite
4878 // by bitcasting a pointer to our canonical type, then loading it if necessary.4878 // by bitcasting a pointer to our canonical type, then loading it if necessary.
4879 const alignment = return_type.abiAlignment(target);4879 const alignment = self.dg.object.target_data.abiAlignmentOfType(abi_ret_ty);
4880 const rp = self.buildAlloca(llvm_ret_ty, alignment);4880 const rp = self.buildAlloca(llvm_ret_ty, alignment);
4881 const ptr_abi_ty = abi_ret_ty.pointerType(0);4881 const ptr_abi_ty = abi_ret_ty.pointerType(0);
4882 const casted_ptr = self.builder.buildBitCast(rp, ptr_abi_ty, "");4882 const casted_ptr = self.builder.buildBitCast(rp, ptr_abi_ty, "");
test/c_abi/main.zig-2
...@@ -917,8 +917,6 @@ test "CFF: C passes to Zig" {...@@ -917,8 +917,6 @@ test "CFF: C passes to Zig" {
917 try expectOk(c_send_CFF());917 try expectOk(c_send_CFF());
918}918}
919test "CFF: C returns to Zig" {919test "CFF: C returns to Zig" {
920 // segfault on aarch64 and mips
921 if (builtin.target.cpu.arch == .aarch64) return error.SkipZigTest;
922 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;920 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
923 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;921 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
924 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;922 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;