<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/79057>79057</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIRV] SPIR-V Backend crashes on creation of a struct with opaque pointer fields
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
VyacheslavLevytskyy
</td>
</tr>
</table>
<pre>
An attempt to use opaque pointer fields in a struct makes SPIR-V Backend crash on the stage of module analysis if the struct has more than one opaque pointer field. For example:
```
@a = addrspace(1) constant i32 123
@struct = addrspace(1) global {ptr addrspace(1), ptr addrspace(1)} { ptr addrspace(1) @a, ptr addrspace(1) @a }
define spir_kernel void @foo() {
ret void
}
```
demonstrates a crash in `SPIRVGeneralDuplicatesTracker::buildDepsGraph()` due to the fact that there is no mandatory records defined in `SPIRVReg2EntryTy Reg2Entry;` for some type references of `OpTypeStruct`: namely, for all opaque pointer type arguments of `OpTypeStruct` after the first one.
The root cause is producing of multiple identical opaque pointer types, i.e., creation of new `OpTypePointer` without checking their existence. Along with inserting just a single record per type into a data structure used for dependencies analysis in `SPIRVGeneralDuplicatesTracker::buildDepsGraph()` this causes missing records in the same data structure for all opaque pointer fields except for the first one.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVMFu4zYQ_Rr6Mogh05YVH3RI6npRoEAXu0GuxYgcSVxTJEuOsqu_Lygr3mzqnAoYkm3ODN-892YwJdM5olqUj6I8rnDk3sf6eULVU7L48ie9TJzO07RqvJ7qBwfITENgYA9jIvAB_xkJgjeOKUJryOoExgFC4jgqhgHPlODr5z--3D3DI6ozOQ0qYurBO-CeIDF2BL6FwevREqBDOyWTwLTL-VyoxwSDjwTcowPvbl--hpOPQD9wCJbE9kEUR1G8PvfF8rn83BUIYnsE1DqmgIqEvN8IeQDlXWJ0DGYrYSO31_gFys2kzvoGLYjqMXD8z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