Commit c6f0ea4
authored
[spirv] Fix crash on some ternary ops (#4534)
Sometimes the Clang AST does not include an implicit cast wrapper around
an integer-type condition in the ternary operator, which causes a crash
when the SPIR-V generated has a non-bool type for the
OpBranchConditional. This change checks for this case and casts the
condition to bool.
Example ASTs:
```
// | `-ConditionalOperator 0x24022c82d48 <col:10, col:19> 'bool'
// | |-ImplicitCastExpr 0x24022c82d00 <col:10> 'bool' <IntegralToBoolean>
// | | `-IntegerLiteral 0x24022c82c58 <col:10> 'literal int' 1
bool b1, b2;
bool b = 1 ? b1 : b2;
// | `-ConditionalOperator 0x1ede5137380 <col:18, col:27> 'SamplerState'
// | |-IntegerLiteral 0x1ede5137308 <col:18> 'literal int' 1
SamplerState s1, s2;
SamplerState s = 1 ? s1 : s2;
```
Fixes #38311 parent 24ea9e8 commit c6f0ea4
2 files changed
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3381 | 3381 | | |
3382 | 3382 | | |
3383 | 3383 | | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
3384 | 3393 | | |
3385 | 3394 | | |
3386 | 3395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
194 | 219 | | |
195 | 220 | | |
196 | 221 | | |
| |||
0 commit comments