aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-17 15:36:12 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-17 15:36:12 -0700
commit07691db3ae061d8122f6c53c1f34c2fb0df2f7ef (patch)
tree379046dbe83b30f007433360ad08d3bdee7e2234 /src/codegen
parent6534f2ef4f8161f4121326f19bc3cf89324f62c5 (diff)
downloadzig-07691db3ae061d8122f6c53c1f34c2fb0df2f7ef.tar.gz
zig-07691db3ae061d8122f6c53c1f34c2fb0df2f7ef.zip
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
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig20
1 files changed, 11 insertions, 9 deletions
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, "");