<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74248>74248</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
backends will turn OOB InsertElement into OOB store
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
llvm:codegen,
miscompilation
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
regehr
</td>
</tr>
</table>
<pre>
here's a slightly modified version of one of our unit tests:
```llvm
define void @insert_store_nonconst_index_not_known_valid_by_and(ptr %p, i8 zeroext %val, i32 %idx) {
%x4 = load <16 x i8>, ptr %p, align 16
%x6 = insertelement <16 x i8> %x4, i8 %val, i32 %idx
store <16 x i8> %x6, ptr %p, align 16
ret void
}
```
the issue is what happens when `%idx` is out of bounds. LangRef says that in this case the insertelement poisons the vector. however, here's what we get on AArch64 (other backends seem similar):
```
insert_store_nonconst_index_not_known_valid_by_and:
strb w1, [x0, w2, uxtw]
ret
```
this is, of course, much worse than a vector full of poison. there would seem to be two solutions. first, bounds-checking on vector element access indices. second, we change LangRef to make this situation immediate UB.
cc @nunoplopes @tanmaytirpankar
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVF2L6zYQ_TXKy7DBlp2vBz9kd-9CoXCh0OcgSxNbXVkymnGc9NcXyb7bve1CoSHImYlm5syZ41FEtvOIjdg9i93rRk3ch9hE7LCPmzaYR9NjRCEPBArI2a5n94AhGHu1aOCGkWzwEK4QPObHFGHyloGRmER1FsWrKM5iXyxf527D4jJ4tR7hFqwBURfWE0a-EIeIFx-8Dp74Yr3B-8UHvrz7MPvLTTlrLu3jorwR8jhyBCF3o5AvYI_wJ8aAd06um3LZWclkWXMX8gTi8LzUTr57DaJ6BReUAVG9lHu4gz2K6luK-5xYOdt5KPefQvc5dIGMDgf0_HOOpcAK60s4S7Lc7heh-_8AEZEzcyu7h9d_0Lya-eQewRJN6YS5Vwy9Gkf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