glslang
glslang copied to clipboard
glslangValidator incorrectly gives error on use of member name length
I have a compute shader that looks like
#version 450
layout (local_size_x = 32) in;
struct A{
uint length;
uint contents[7];
};
restrict layout(std430, set = 0, binding = 2) buffer SuperBuffer{
A collision_grid[1024];
};
void main()
{
uint gID = gl_GlobalInvocationID.x;
atomicAdd(collision_grid[gID].length, 1);
}
When I run glslc my_shader.comp -o o.spv
I get Segmentation fault (core dumped)
. However, if I rename length
variable to something else, the compilation passes successfully.
My compiler version
$ glslc --version
shaderc v2021.2-dev unknown hash, 2021-06-25
spirv-tools v2021.3-dev unknown hash, 2021-06-25
glslang unknown hash, 2021-06-25
Target: SPIR-V 1.0
My system
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
Vulkan
Vulkan Instance Version: 1.2.182
As you may know, the name length is a pre-defined method for all array, vector and matrix types. It is also the name of a set of built-in functions which can be redefined by the user.
It is true that the GLSL spec does not explicitly say that the name length cannot be used in this context. It also seems that a more "enlightened" front-end might actually allow such a use. Still, fixing this problem will likely not rise to the top of my work queue in the near future.
In the meantime, I would suggest the workaround of renaming this member.
glslangValidator does not segfault on Windows, although it does give a not-entirely-correct error message so I will keep this issue open. We will shortly investigate if this segfault can be reproduced with glslangValidator on ubuntu. If it cannot, I will suggest you open an issue with shaderc.
glslangValidator on ubuntu does not crash but gives pretty much the same error as on Windows:
john@neon:/tmp$ glslangValidator -V --target-env spirv1.0 -o t.comp.spv t.comp
t.comp
ERROR: t.comp:17: 'length' : does not operate on this type: layout( column_major std430 offset=0) restrict temp structure{ global highp uint length, layout( std430) global 7-element array of highp uint contents}
ERROR: t.comp:17: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.
SPIR-V is not generated for failed compile or link
Please submit the segfault crash to shaderc.
I will change the title of this issue to better fit the glslangValidator behavior.