| ... | ... | @@ -5324,14 +5324,22 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5324 | 5324 | |
| 5325 | 5325 | const inst_ty = f.air.typeOfIndex(inst); |
| 5326 | 5326 | const payload = try f.resolveInst(ty_op.operand); |
| 5327 | | if (inst_ty.optionalReprIsPayload()) return payload; |
| 5327 | try reap(f, inst, &.{ty_op.operand}); |
| 5328 | const writer = f.object.writer(); |
| 5329 | |
| 5330 | if (inst_ty.optionalReprIsPayload()) { |
| 5331 | const local = try f.allocLocal(inst, inst_ty); |
| 5332 | try f.writeCValue(writer, local, .Other); |
| 5333 | try writer.writeAll(" = "); |
| 5334 | try f.writeCValue(writer, payload, .Other); |
| 5335 | try writer.writeAll(";\n"); |
| 5336 | return local; |
| 5337 | } |
| 5328 | 5338 | |
| 5329 | 5339 | const payload_ty = f.air.typeOf(ty_op.operand); |
| 5330 | 5340 | const target = f.object.dg.module.getTarget(); |
| 5331 | 5341 | const is_array = lowersToArray(payload_ty, target); |
| 5332 | 5342 | |
| 5333 | | try reap(f, inst, &.{ty_op.operand}); |
| 5334 | | const writer = f.object.writer(); |
| 5335 | 5343 | const local = try f.allocLocal(inst, inst_ty); |
| 5336 | 5344 | if (!is_array) { |
| 5337 | 5345 | try f.writeCValue(writer, local, .Other); |
| ... | ... | @@ -5340,9 +5348,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5340 | 5348 | try writer.writeAll("; "); |
| 5341 | 5349 | } |
| 5342 | 5350 | try f.writeCValue(writer, local, .Other); |
| 5343 | | try writer.writeAll(".is_null = "); |
| 5344 | | try f.object.dg.renderValue(writer, Type.bool, Value.false, .Initializer); |
| 5345 | | try writer.writeAll(";\n"); |
| 5351 | try writer.writeAll(".is_null = false;\n"); |
| 5346 | 5352 | if (is_array) { |
| 5347 | 5353 | try writer.writeAll("memcpy("); |
| 5348 | 5354 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); |