diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-09-14 13:49:54 -0700 |
|---|---|---|
| committer | Cody Tapscott <topolarity@tapscott.me> | 2022-10-21 10:44:20 -0700 |
| commit | 724d75363855176aa5e6b3d9bcd1656e2cc1f6a6 (patch) | |
| tree | f3b5c2e68dcc355ade60e3c75065002715040790 /src/codegen/llvm.zig | |
| parent | 3007fdde45868142654d0bfa59bc0e17e5f24a1c (diff) | |
| download | zig-724d75363855176aa5e6b3d9bcd1656e2cc1f6a6.tar.gz zig-724d75363855176aa5e6b3d9bcd1656e2cc1f6a6.zip | |
stage2: Add `.save_err_return_trace_index` AIR op
This is encoded as a primitive AIR instruction to resolve one corner
case: A function may include a `catch { ... }` or `else |err| { ... }`
block but not call any errorable fn. In that case, there is no error
return trace to save the index of and codegen needs to avoid
interacting with the non-existing error trace.
By using a primitive AIR op, we can depend on Liveness to mark this
unused in this corner case.
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index b0d1588007..3ebca13c20 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -4592,6 +4592,7 @@ pub const FuncGen = struct { .errunion_payload_ptr_set => try self.airErrUnionPayloadPtrSet(inst), .err_return_trace => try self.airErrReturnTrace(inst), .set_err_return_trace => try self.airSetErrReturnTrace(inst), + .save_err_return_trace_index => try self.airSaveErrReturnTraceIndex(inst), .wrap_optional => try self.airWrapOptional(inst), .wrap_errunion_payload => try self.airWrapErrUnionPayload(inst), @@ -6543,6 +6544,24 @@ pub const FuncGen = struct { return null; } + fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value { + if (self.liveness.isUnused(inst)) return null; + + const target = self.dg.module.getTarget(); + + const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; + //const struct_ty = try self.resolveInst(ty_pl.ty); + const struct_ty = self.air.getRefType(ty_pl.ty); + const field_index = ty_pl.payload; + + var ptr_ty_buf: Type.Payload.Pointer = undefined; + const llvm_field_index = llvmFieldIndex(struct_ty, field_index, target, &ptr_ty_buf).?; + const struct_llvm_ty = try self.dg.lowerType(struct_ty); + const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, self.err_ret_trace.?, llvm_field_index, ""); + const field_ptr_ty = Type.initPayload(&ptr_ty_buf.base); + return self.load(field_ptr, field_ptr_ty); + } + fn airWrapOptional(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value { if (self.liveness.isUnused(inst)) return null; |
