<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69301>69301</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[GVN] Use after free during load PRE
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:crash
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
nikic
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nikic
</td>
</tr>
</table>
<pre>
```llvm
; RUN: opt -S -passes=gvn < %s
define i64 @test(i1 %c, ptr %p) {
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %add, %loop.latch ]
%ptr.iv = phi ptr [ %p, %entry ], [ %select, %loop.latch ]
%icmp = icmp eq i64 %iv, 0
br i1 %icmp, label %exit, label %loop.cont
loop.cont:
%add = add i64 %iv, -1
br i1 %c, label %exit, label %loop.latch
loop.latch:
%load = load i64, ptr %ptr.iv, align 8
%load6 = load i64, ptr null, align 8
%icmp7 = icmp ugt i64 %load, %load6
%select = select i1 %icmp7, ptr %ptr.iv, ptr null
br label %loop
exit:
%res = load i64, ptr %ptr.iv, align 8
ret i64 %res
}
```
Produces a use after free.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVF1v4ygU_TXXLygWBhvHD35Ims2-VVVX3XcMxGaX2B7A1fTfjwBPPtpqpiNFMVzfc869x3C5c7oflWqh2gMho_5fCyAEqkPGFz9Mto2hrJvkWwsMp58xr2fAB8A7oHv0_PIIdIem2aPNP2gzc-eUA3roX0cE9AEBqVzKluqkR4U0KxGU2CvngWx1ETIEkAc0exvWM5AGQb1PIDV6-wZ0l3YIdRYZ3ikTMs00zWsh8T_ur6lAKv2KgB7QPOgkW-0RDlJAqkiMoDrEfbUPMS7l-jZQ5YZ7McSUK-PsbX7DGmtO4PkXxE4ZJfzvuLU4z5E5LtS3VHPoIiDxjQXJtZAW3lwMUd-1vwtEKTGN_r1NKXjnFZcyiofnnfCm-KAsviAbO_ygm6J3wmbiSTkuNCtvD0O0OwS40f2Itu9w7FPguBjzOSZYVl89Xnr_s9fAcflAXLIbUPp6EbUur_7XnxZ7KeILpza6d2eIVe6P_bDq0olV64WDej1dl6ubtk92kotQDnG0OIX4ySuLTlapPJMtlQ1teKbagjV1RYumKbOhlazrKnZiDAtxKktcEclJQWrZUMZJ12W6JZjQAhc13tKmKnMpSCdPhG4b1nDZKSixOnNt8jA-8sn2mXZuUS1rKC6y6I5b51AcMHQnLHfDOo5sG4KbbukdlNho592VyGtv4gz7-99HqA7o5a4pJBerxz65-fT8V7ZY0w7ezy64To5Ajr32w9LlYjoDOUb19NjMdvovXtxjLNYBOcZ6fwQAAP__aaZ7BQ">