yum-mirror/glslang

git clone https://git.yummers.dev/yum-mirror/glslang

Zackery Mason-BlaugLiveTraverser no longer traverses switch cases that are statically not accessed0b3e8560

main
2.7 KiB130 linesraw
1#version 460
2
3layout(location = 0) in vec4 a0; // accessed
4layout(location = 1) in vec4 a1; // accessed
5layout(location = 2) in vec4 a2; // accessed
6layout(location = 3) in vec4 a3; // accessed
7layout(location = 4) in vec4 a4; // accessed
8layout(location = 5) in vec4 a5; // accessed
9layout(location = 6) in vec4 a6; // accessed
10layout(location = 7) in vec4 a7; // accessed
11layout(location = 8) in vec4 a8; // accessed
12layout(location = 9) in vec4 a9; // accessed
13layout(location = 10) in vec4 a10; // accessed
14layout(location = 11) in vec4 n0; // not accessed
15layout(location = 12) in vec4 n1; // not accessed
16layout(location = 13) in vec4 n2; // not accessed
17layout(location = 14) in vec4 n3; // not accessed
18layout(location = 15) in vec4 n4; // not accessed
19layout(location = 16) in vec4 n5; // not accessed
20layout(location = 17) in vec4 n6; // not accessed
21layout(location = 18) in vec4 n7; // not accessed
22layout(location = 19) in vec4 n8; // not accessed
23layout(location = 20) in vec4 n9; // not accessed
24
25void main() {
26    // empty case is live
27    switch (2) {
28    case 2: break;
29    case 1:
30        gl_Position = n0;
31    }
32
33    // empty default case is live
34    switch (3) {
35    default: break;
36    case 1:
37        gl_Position = n1;
38    }
39
40    // no live case
41    switch (3) {
42    case 2: // fallthrough
43    case 1:
44        gl_Position = n2;
45    }
46
47    // ensure break is handled correctly
48    switch (1) {
49    case -1:
50        gl_Position = n3;
51        break;
52    case 1:
53        gl_Position = a0;
54        break;
55        gl_Position = n4;
56    case 0:
57        gl_Position = n5;
58    }
59
60    const int cx = 1;
61
62    // signed/unsigned mismatch
63    switch (cx) {
64    case uint(1):
65        gl_Position = a1;
66    }
67
68    // signed/unsigned conversion
69    switch (-1) {
70    case ~uint(0):
71        gl_Position = a2;
72    }
73
74    // const variable case
75    switch (1) {
76    case cx:
77        gl_Position = a3;
78        break;
79    case -1:
80        gl_Position = n6;
81    }
82
83    // fallthrough with const variable
84    switch (cx) {
85    default: // fallthrough
86    case 2:
87        gl_Position = a4;
88    }
89
90    // non-trivial constant expression
91    switch (((cx + 1) * 2) - 3) {
92    case 1:
93        gl_Position = a5;
94        break;
95    case 2:
96        gl_Position = n7;
97    }
98
99    // expression as case
100    switch (5 + 3) {
101    case 6 + 2:
102        gl_Position = a6;
103        break;
104    case 5 + 2:
105        gl_Position = n8;
106        break;
107    }
108
109    int x = 2;
110
111    // liveness of non-const variables cannot be deduced
112    switch (x) {
113    case 1:
114        gl_Position = a7;
115        break;
116    case 2:
117        gl_Position = a8;
118        break;
119    }
120
121    // const and non-const expression
122    switch (cx + x) {
123    case 1:
124        gl_Position = a9;
125        break;
126    case 3:
127        gl_Position = a10;
128        break;
129    }
130}