Miscompilation of a switch case
System information
System: Kernel: 5.11.0-18-generic x86_64 bits: 64 compiler: gcc v: 10.2.1 Desktop: GNOME 3.38.4
tk: GTK 3.24.25 wm: gnome-shell dm: GDM3 Distro: Ubuntu 21.04 (Hirsute Hippo)
CPU: Info: 6-Core model: Intel Core i7-8750H bits: 64 type: MT MCP arch: Kaby Lake note: check rev: A L2 cache: 9 MiB
flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 52799
Speed: 900 MHz min/max: 800/4100 MHz Core speeds (MHz): 1: 900 2: 900 3: 900 4: 900 5: 900 6: 900 7: 900 8: 901
9: 900 10: 900 11: 900 12: 900
Graphics: Device-1: Intel CoffeeLake-H GT2 [UHD Graphics 630] vendor: ASUSTeK driver: i915 v: kernel bus ID: 00:02.0
chip ID: 8086:3e9b
Device-2: NVIDIA GP107M [GeForce GTX 1050 Ti Mobile] vendor: ASUSTeK driver: nvidia v: 460.80 bus ID: 01:00.0
chip ID: 10de:1c8c
Display: x11 server: X.Org 1.20.11 compositor: gnome-shell driver: loaded: modesetting,nvidia
unloaded: fbdev,nouveau,vesa resolution: 1: 1920x1080~120Hz 2: 1920x1080~60Hz s-dpi: 96
OpenGL: renderer: llvmpipe (LLVM 12.0.0 256 bits) v: 4.5 Mesa 21.1.5 compat-v: 3.1 direct render: Yes
Describe the issue
The side-effecting instruction of the following switch does not seem to be executed.
#version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std430, binding = 0) buffer buffer_0 {
int ext_0; // 0
int ext_1; // 5
int ext_2; // 0
} ;
void main()
{
ext_0 += ext_1; // ext_0 = 5
switch(ext_1 ^= ext_0) // ext_0 = 5 ^ 5 = 0
{
case 0:
ext_2 = 1;
break;
case 5:
ext_2 = 2;
break;
}
}
At the end of the execution, the shader storage block contains:
5 5 2
I would expect the shader storage block to contain instead:
5 0 1
Reproducing the issue
The shader has been found using a testing tool called Shadertrap. Instructions are given below to reproduce it with that tool. A shader_test is also attached for convenience. shader04.shader_test
- Get or build Shadertrap:
- A build version of Shadertrap for linux can be found on Shadertrap release repository.
- To build from source, please refer to Shadertrap repository
- Ge the shader file shader04.shadertrap
- Execute the Shadertrap command
bin/shadertrap shader04.shadertrap
- Collect the buffer results in the execution folder (one file per buffer)
Edited by Marcin Ślusarz