<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119641>119641</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] `packoffset` validation does not handle 16-bit types well
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            HLSL
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          hekota
      </td>
    </tr>
</table>

<pre>
    Packoffset layout validation assumes all struct fields are aligned to 4 bytes. That is not true for fields with 16-bit types which are aligned to 2 bytes.

For example this is valid on DXC while Clang reports `error: packoffset overlap between 'f', 's'`:
https://godbolt.org/z/5eqTerhvY

```
struct S {
 half a;
  half b;
  half c;
  half d;
  half e;
  half f;
  half g;
 half h;
};

cbuffer CB0 {
  S s : packoffset(c0.x);
  float f : packoffset(c1.x);
}
```

DXC layout:
```
; cbuffer CB0
; {
;
; struct CB0
;   {
;
;       struct struct.S
;       {
;
;           half a;                                   ; Offset:    0
;           half b; ; Offset:    2
;           half c; ; Offset:    4
;           half d; ; Offset:    6
;           half e; ; Offset:    8
;           half f;                                   ; Offset:   10
;           half g;                                   ; Offset: 12
;           half h;                                   ; Offset:   14

;       } s;                                          ; Offset: 0
;
;       float f;                                      ; Offset:   16

;   } CB0;                                            ; Offset:    0 Size:    20
;
; }
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVU9voz4Q_TTmMmpkzJ-UAweSCP0OlX4rpYfdo8FD8NaJs7ZJm376lYFsQ0q13VpI-MHz85th8HBr5e6AmJNkRZJNwDvXapO3-KQdDyotzvk3Xj_pprHoQPGz7hycuJKCO6kPwK3t9miBKwXWma520EhUwgI3CFx5cQFOQwzV2aFdwGPLHUgLB-3AmQ6h0eay5lm6FsL0rpIO3PmIFp5bWbe3WmzUIrQgtCi1AXzh-6NCcK20Xrx3CPoAm-9rr6EQ1oofdmDwqI2zQFKKxmhDogKObwHqExrFj1Che0Y8AGHLhrAlYWs_tX6aUhL5bVvnjtZPWUlYudOi0sottNkRVr4SVib46xFNe_oxuPTrhosWY6K2QJYrQgtouWqAk6gHA6omqJ4gMUE4Qc0E7UbUg3YAZLkZJ7Soq65p0MB6RS9eYAsWplkh7L6mixfCsot4ozR30Mzwwiue32kaOKGF_yBDGQ1pnLyOVnBlaXwyGBslo9WlzN4I8I4yjJE43Bbbybv5FX78-Rjw9-FZ_w-xR4V_QOflqj6OWzKbJ9ez5HieLGbJ6TwZZ8n38-TmaykIP0jB7ity4Qcpar_o7ZLEm1LYgP2c4KwunSmk8Qf5tOo7p-mtU-_Sl_y_-JwrUNjKV7wU4NT6-_81EHkksijjAebhMoqyNI4iGrQ5pbVgmCRNRmtR0aVgVYaiSuOYNaxaikDmjLI4ZCGjNE4iushqGgmWhBmmcZPVlMQU91yqhVKnvT82A2lth3kYZmkcBopXqGzflRj772H7QBjz_cnknn9XdTtLYqqkdfZNwUmn-k7WL0g2_pS_Op5Set25hMahCbX8IBTetB1UKuiMym9OeenarlrUek9Y6bcdb3dHo39i7Qgr-ygsYeUYyClnvwMAAP__nz3wyw">