<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/145439>145439</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DirectX] Root signature's `DescriptorTableView` has undefined behaviour for version 1.0 root signatures.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:DirectX
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bogner
</td>
</tr>
</table>
<pre>
We currently have the "DescriptorTableView" load a `DirectX::DescriptorTable` with a type like so:
```c++
struct DescriptorTable {
uint32_t NumRanges;
uint32_t RangesOffset;
ViewArray<dxbc::RTS0::v2::DescriptorRange> Ranges;
};
```
However, we set up the ranges view like so:
```c++
size_t RangeSize = sizeof(dxbc::RTS0::v1::DescriptorRange);
if (Version > 1)
RangeSize = sizeof(dxbc::RTS0::v2::DescriptorRange);
Table.Ranges.Stride = RangeSize;
Table.Ranges.Data =
ParamData.substr(2 * sizeof(uint32_t), Table.NumRanges * RangeSize);
```
This invokes undefined behaviour. It is not legal to store a `dxbc::RTS0::v1::DescriptorRange` in an object of type `dxbc::RTS0::v2::DescriptorRange` (the inheritance is in the other direction. Furthermore, `dxbc::RTS0::v2::DescriptorRange` will not fit in `sizeof(dxbc::RTS0::v1::DescriptorRange)`, and the last field (currently `Flags`) will overlap with the next object.
Note: this may become moot depending on the fix to #145438, as that issue implies that we won't be able to have an inheritance relationship between the versions of DescriptorRange at all.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVVFv4zYM_jXKC3GGIseO8-CHXLNge7kNbXHb2yDbdKxVlgyJttv79YPkpFmDFkMPMGBBosiP30eR0nt1Mogly76y7LCSI3XWlZU9GXSryjYv5Z8I9egcGtIv0MkJgToEJsQBfe3UQNY9ykrjd4UzEwK0lQ1IYDk_KIc1_cXSPUv3N9Ys5zAr6kACvQwIWj0heBts-Z7lfPlqJr6Gj-89ubEmuPECbBsOAUZlKBV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