authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-11 00:04:11+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-05-11 20:31:51+02:00
log435a5660ce62c9c54f8ac9bf0a325811a6b684e6
treeaa930f3bd62b83023dba214df245bcb8f64cc694
parentf62735d98ce9055ca08cff587e438412404818cd
signaturelock-open Commit is signed but in an unrecognized format.

spirv: fix invalid code generated by br-with-value

The result-id and result-type-id of the OpPhi used to merge the break values was not properly emitted, as some of the operands were not written out. This caused an invalid spir-v module.

1 files changed, 2 insertions(+), 2 deletions(-)

src/codegen/spirv.zig+2-2
......@@ -2291,15 +2291,15 @@ pub const DeclGen = struct {
22912291 return null;
22922292
22932293 // Combine the result from the blocks using the Phi instruction.
2294
22952294 const result_id = self.spv.allocId();
22962295
22972296 // TODO: OpPhi is limited in the types that it may produce, such as pointers. Figure out which other types
22982297 // are not allowed to be created from a phi node, and throw an error for those.
22992298 const result_type_id = try self.resolveTypeId(ty);
2300 _ = result_type_id;
23012299
23022300 try self.func.body.emitRaw(self.spv.gpa, .OpPhi, 2 + @intCast(u16, incoming_blocks.items.len * 2)); // result type + result + variable/parent...
2301 self.func.body.writeOperand(spec.IdResultType, result_type_id);
2302 self.func.body.writeOperand(spec.IdRef, result_id);
23032303
23042304 for (incoming_blocks.items) |incoming| {
23052305 self.func.body.writeOperand(spec.PairIdRefIdRef, .{ incoming.break_value_id, incoming.src_label_id });