Skip to content

Invalid SPIR-V generated for specialization constant based expression #4351

Description

@mplatings

Description

glslang inconsistently lowers specialization-constant expressions involving && or ||.

When the right operand is itself a compound specialization-constant expression, the logical operation can be lowered to function control flow with an OpPhi. However, glslang continues treating the result as a specialization constant. A subsequent operation on that result is emitted as a module-scope OpSpecConstantOp referencing the function-local OpPhi, producing invalid SPIR-V.

To reproduce

With glslang 11:16.2.0:

$ cat reproducer.comp
#version 460

layout(constant_id = 0) const uint a = 0u;
const bool c = (a == 0u) && (a + 1u == 1u);

layout(local_size_x = 1) in;

void main() {
    if (!c)
        return;
}
$ glslang -V --target-env vulkan1.1 reproducer.comp -o reproducer.spv
reproducer.comp
$ spirv-val --target-env vulkan1.1 reproducer.spv
error: line 22: ID '16[%c]' has not been defined
  %17 = OpSpecConstantOp %bool LogicalNot %c

Metadata

Metadata

Assignees

Labels

SPIR-Vbugsev:miscompileGiven a valid input, glslang produces incorrect or invalid SPIR-V

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions