Commit 020fbdf
authored
[SPIR-V] Fixed a crash if encounter constant buffer fields with overlapping register assignments (microsoft#7636)
The issue:
simple vertex shader like so
```
uniform float4x4 gMVP : register(c0);
uniform float4 gFoo : register(c5);
uniform float4 gBar : register(c5);
float4 main(float4 pos : POSITION) : SV_Position {
return mul(gMVP, pos * gFoo + gBar);
}
```
will result in an internal crash
```
dxc.exe -spirv -T vs_6_2 -E main test.hlsl -Fo test.spirv
Internal compiler error: access violation. Attempted to read from address 0x0000000000000000
```
Due to `LowerTypeVisitor` trying to assign offsets to fields without
explicit locations.
It'll sort fields first, which will fill the map with the fields first.
And since it's using `std::map` - if there's fields with the same
`register` number - it'll only insert first, other will be left out,
resulting nullptrs in the output vector.
We read the content of the vector down the road crashing.
My change fixes the crash and tries to output somewhat useful info about
compilation fail.
I hope this helps you in fixing it properly, or you can take it as it
is.1 parent 162bf4e commit 020fbdf
File tree
3 files changed
+55
-28
lines changed- tools/clang
- lib/SPIRV
- test/CodeGenSPIRV
3 files changed
+55
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 40 | | |
68 | 41 | | |
69 | 42 | | |
| |||
292 | 265 | | |
293 | 266 | | |
294 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
295 | 299 | | |
296 | 300 | | |
297 | 301 | | |
| |||
1378 | 1382 | | |
1379 | 1383 | | |
1380 | 1384 | | |
| 1385 | + | |
| 1386 | + | |
1381 | 1387 | | |
1382 | 1388 | | |
1383 | 1389 | | |
1384 | 1390 | | |
1385 | 1391 | | |
1386 | 1392 | | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1387 | 1398 | | |
1388 | 1399 | | |
1389 | 1400 | | |
| |||
1397 | 1408 | | |
1398 | 1409 | | |
1399 | 1410 | | |
1400 | | - | |
1401 | 1411 | | |
1402 | 1412 | | |
1403 | 1413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments