KhronosGroup / KhronosGroup/glslang

Warn about bogus comparisons

Open
#775 1 comment 0 reactions 0 assignees View on GitHub
enhancement SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

Today, someone filed a [bug against our Vulkan driver](https://bugs.freedesktop.org/show_bug.cgi?id=100134) 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.

Contributor guide

Open the contributing guide

Research direction

Start with the supplied GLSL compute shader and compare its unsigned `i >= 0` condition with GCC's `-Wsign-compare` behavior. Trace how glslang handles comparisons and diagnostics, then verify that an appropriate warning is emitted for this always-true comparison without changing valid shader compilation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.