From 07691db3ae061d8122f6c53c1f34c2fb0df2f7ef Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 17 Oct 2021 15:36:12 -0700 Subject: stage2: fix handling of error unions as return type * LLVM backend: fix phi instruction not respecting `isByRef` - Also fix `is_non_null` not respecting `isByRef` * Type: implement abiSize for error unions --- src/codegen/llvm.zig | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 026046b29f..e8bfbef587 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1804,14 +1804,16 @@ pub const FuncGen = struct { const raw_llvm_ty = try self.dg.llvmType(inst_ty); - // If the zig tag type is a function, this represents an actual function body; not - // a pointer to it. LLVM IR allows the call instruction to use function bodies instead - // of function pointers, however the phi makes it a runtime value and therefore - // the LLVM type has to be wrapped in a pointer. - const llvm_ty = if (inst_ty.zigTypeTag() == .Fn) - raw_llvm_ty.pointerType(0) - else - raw_llvm_ty; + const llvm_ty = ty: { + // If the zig tag type is a function, this represents an actual function body; not + // a pointer to it. LLVM IR allows the call instruction to use function bodies instead + // of function pointers, however the phi makes it a runtime value and therefore + // the LLVM type has to be wrapped in a pointer. + if (inst_ty.zigTypeTag() == .Fn or isByRef(inst_ty)) { + break :ty raw_llvm_ty.pointerType(0); + } + break :ty raw_llvm_ty; + }; const phi_node = self.builder.buildPhi(llvm_ty, ""); phi_node.addIncoming( @@ -2315,7 +2317,7 @@ pub const FuncGen = struct { return self.builder.buildICmp(op, loaded, zero, ""); } - if (operand_is_ptr) { + if (operand_is_ptr or isByRef(err_union_ty)) { const err_field_ptr = self.builder.buildStructGEP(operand, 0, ""); const loaded = self.builder.buildLoad(err_field_ptr, ""); return self.builder.buildICmp(op, loaded, zero, ""); -- cgit v1.2.3