Description
When translating WGSL atomicSub to GLSL, naga emulates it with atomicAdd by prepending - to the operand (https://github.com/gfx-rs/wgpu/blob/trunk/naga/src/back/glsl/writer.rs#L2130-L2131)). The operand is written without parentheses, so if the operand expression itself begins with -, which is the case for a negative integer literal, the output contains --, which the GLSL lexer tokenizes as the decrement operator, producing invalid GLSL.
Repro steps
var<workgroup> a: atomic<i32>;
@compute @workgroup_size(1)
fn main() {
let x = atomicSub(&a, -1i);
}
naga repro.wgsl nagarepro.comp --shader-stage compute --entry-point main --input-kind wgsl
which produces
int _e2 = atomicAdd(a, --1);
which glslang rejects with
ERROR: 0:17: '--' : l-value required (can't modify a const)
ERROR: 0:17: '--' : wrong operand type no operation '--' exists that takes an operand of type const int (or there is no acceptable conversion)
ERROR: 0:17: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
Description
When translating WGSL
atomicSubto GLSL, naga emulates it withatomicAddby prepending-to the operand (https://github.com/gfx-rs/wgpu/blob/trunk/naga/src/back/glsl/writer.rs#L2130-L2131)). The operand is written without parentheses, so if the operand expression itself begins with-, which is the case for a negative integer literal, the output contains--, which the GLSL lexer tokenizes as the decrement operator, producing invalid GLSL.Repro steps
naga repro.wgsl nagarepro.comp --shader-stage compute --entry-point main --input-kind wgslwhich produces
which glslang rejects with