authorgravatar for vasyapulopapik@gmail.comKleshzz <vasyapulopapik@gmail.com> 2026-07-22 09:34:43+02:00
committergravatar for alichraghi@noreply.codeberg.orgAli Cheraghi <alichraghi@noreply.codeberg.org> 2026-07-22 09:34:43+02:00
log2b1c6633aaf1d59d4affd88e87a507a02836c478
treec1046dac1a105a1df1ee21e97ebb6c31f5fb7d61
parentf22d73386441714d59ea080f165979e18204a09d

spirv: fix ICEs when indexing slices, emitting large instructions (#36253)

Fixes #36229 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36253 Reviewed-by: Ali Cheraghi <alichraghi@noreply.codeberg.org>

1 files changed, 6 insertions(+), 3 deletions(-)

src/codegen/spirv/Section.zig+6-3
...@@ -49,8 +49,9 @@ pub fn emitRaw(...@@ -49,8 +49,9 @@ pub fn emitRaw(
49 operand_words: usize,49 operand_words: usize,
50) !void {50) !void {
51 const word_count = 1 + operand_words;51 const word_count = 1 + operand_words;
52 if (word_count > std.math.maxInt(u16)) return error.OutOfMemory;
52 try section.instructions.ensureUnusedCapacity(allocator, word_count);53 try section.instructions.ensureUnusedCapacity(allocator, word_count);
53 section.writeWord((@as(Word, @intCast(word_count << 16))) | @backingInt(opcode));54 section.writeWord((@as(Word, @intCast(word_count)) << 16) | @backingInt(opcode));
54}55}
5556
56/// Write an entire instruction, including all operands57/// Write an entire instruction, including all operands
...@@ -70,7 +71,8 @@ pub fn emitAssumeCapacity(...@@ -70,7 +71,8 @@ pub fn emitAssumeCapacity(
70 operands: opcode.Operands(),71 operands: opcode.Operands(),
71) !void {72) !void {
72 const word_count = instructionSize(opcode, operands);73 const word_count = instructionSize(opcode, operands);
73 section.writeWord(@as(Word, @intCast(word_count << 16)) | @backingInt(opcode));74 if (word_count > std.math.maxInt(u16)) return error.OutOfMemory;
75 section.writeWord((@as(Word, @intCast(word_count)) << 16) | @backingInt(opcode));
74 section.writeOperands(opcode.Operands(), operands);76 section.writeOperands(opcode.Operands(), operands);
75}77}
7678
...@@ -81,8 +83,9 @@ pub fn emit(...@@ -81,8 +83,9 @@ pub fn emit(
81 operands: opcode.Operands(),83 operands: opcode.Operands(),
82) !void {84) !void {
83 const word_count = instructionSize(opcode, operands);85 const word_count = instructionSize(opcode, operands);
86 if (word_count > std.math.maxInt(u16)) return error.OutOfMemory;
84 try section.instructions.ensureUnusedCapacity(allocator, word_count);87 try section.instructions.ensureUnusedCapacity(allocator, word_count);
85 section.writeWord(@as(Word, @intCast(word_count << 16)) | @backingInt(opcode));88 section.writeWord((@as(Word, @intCast(word_count)) << 16) | @backingInt(opcode));
86 section.writeOperands(opcode.Operands(), operands);89 section.writeOperands(opcode.Operands(), operands);
87}90}
8891