Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about bogus comparisons #775

Open
gfxstrand opened this issue Mar 15, 2017 · 1 comment
Open

Warn about bogus comparisons #775

gfxstrand opened this issue Mar 15, 2017 · 1 comment

Comments

@gfxstrand
Copy link
Contributor

gfxstrand commented Mar 15, 2017

Today, someone filed a bug against our Vulkan driver saying that it hangs when you try to run the following compute shader compiled, I believe, with glslang:

#version 450
#extension GL_ARB_separate_shader_objects : enable

shared int roi[8];

void main() {
  for (uint i = 7; i >= 0; i--) {
    roi[i] = 1;
  }
}

The problem with the shader was that they used an unsigned integer for i and a condition of i >= 0 which always evaluates to true yielding an infinite loop. Since we do nothing in our Vulkan driver to guard against infinite loops (why would we?) they got a GPU hang.

It would be really nice if glslang could emit some sort of a warning when someone tries to do an unsafe comparison in a similar way to what GCC does with -Wsign-compare. If it had such a warning, they probably would never have even submitted the bug.

@elmar-k
Copy link

elmar-k commented Dec 8, 2023

Hi,
unfortunately I just lost two full days hunting down a similar case in my own shader. This 'uint' comparison pitfalls happens often when converting OpenCL code to GLSL/Vulkan, because things that work with 'int' in OpenCL often require 'uint' in GLSL/Vulkan, and then you overlook the comparison. Catching such simple bugs would really be important!
Thanks,
Elmar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants