| ... | ... | @@ -402,7 +402,7 @@ pub const DeclGen = struct { |
| 402 | 402 | return result_id; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | | fn genUndef(self: *DeclGen, ty_ref: SpvType.Ref) Error!IdRef { |
| 405 | fn constUndef(self: *DeclGen, ty_ref: SpvType.Ref) Error!IdRef { |
| 406 | 406 | const result_id = self.spv.allocId(); |
| 407 | 407 | try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpUndef, .{ .id_result_type = self.typeId(ty_ref), .id_result = result_id }); |
| 408 | 408 | return result_id; |
| ... | ... | @@ -1597,7 +1597,7 @@ pub const DeclGen = struct { |
| 1597 | 1597 | .block => try self.airBlock(inst), |
| 1598 | 1598 | |
| 1599 | 1599 | .load => try self.airLoad(inst), |
| 1600 | | .store => return self.airStore(inst), |
| 1600 | .store => return self.airStore(inst), |
| 1601 | 1601 | |
| 1602 | 1602 | .br => return self.airBr(inst), |
| 1603 | 1603 | .breakpoint => return, |
| ... | ... | @@ -1612,6 +1612,8 @@ pub const DeclGen = struct { |
| 1612 | 1612 | .switch_br => return self.airSwitchBr(inst), |
| 1613 | 1613 | .unreach => return self.airUnreach(), |
| 1614 | 1614 | |
| 1615 | .unwrap_errunion_err => try self.airErrUnionErr(inst), |
| 1616 | |
| 1615 | 1617 | .assembly => try self.airAssembly(inst), |
| 1616 | 1618 | |
| 1617 | 1619 | .call => try self.airCall(inst, .auto), |
| ... | ... | @@ -2535,6 +2537,30 @@ pub const DeclGen = struct { |
| 2535 | 2537 | return try self.extractField(payload_ty_ref, err_union_id, eu_layout.payloadFieldIndex()); |
| 2536 | 2538 | } |
| 2537 | 2539 | |
| 2540 | fn airErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2541 | if (self.liveness.isUnused(inst)) return null; |
| 2542 | |
| 2543 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 2544 | const operand_id = try self.resolve(ty_op.operand); |
| 2545 | const err_union_ty = self.air.typeOf(ty_op.operand); |
| 2546 | const err_ty_ref = try self.resolveType(Type.anyerror, .direct); |
| 2547 | |
| 2548 | if (err_union_ty.errorUnionSet().errorSetIsEmpty()) { |
| 2549 | // No error possible, so just return undefined. |
| 2550 | return try self.constUndef(err_ty_ref); |
| 2551 | } |
| 2552 | |
| 2553 | const payload_ty = err_union_ty.errorUnionPayload(); |
| 2554 | const eu_layout = self.errorUnionLayout(payload_ty); |
| 2555 | |
| 2556 | if (!eu_layout.payload_has_bits) { |
| 2557 | // If no payload, error union is represented by error set. |
| 2558 | return operand_id; |
| 2559 | } |
| 2560 | |
| 2561 | return try self.extractField(err_ty_ref, operand_id, eu_layout.errorFieldIndex()); |
| 2562 | } |
| 2563 | |
| 2538 | 2564 | fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 2539 | 2565 | const target = self.getTarget(); |
| 2540 | 2566 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |