<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/135828>135828</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[PGOInstrUse] "dereferencing end() iterator" on unreachable block
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aeubanks
</td>
</tr>
</table>
<pre>
```
diff --git a/llvm/test/Transforms/PGOProfile/Inputs/musttail_pgo-instr-use.proftext b/llvm/test/Transforms/PGOProfile/Inputs/musttail_pgo-instr-use.proftext
new file mode 100644
index 000000000000..9be174fb32bc
--- /dev/null
+++ b/llvm/test/Transforms/PGOProfile/Inputs/musttail_pgo-instr-use.proftext
@@ -0,0 +1,9 @@
+# IR level Instrumentation Flag
+:ir
+foo
+# Func Hash:
+742261418966908927
+# Num Counters:
+1
+# Counter Values:
+1
diff --git a/llvm/test/Transforms/PGOProfile/musttail_pgo-instr-use.ll b/llvm/test/Transforms/PGOProfile/musttail_pgo-instr-use.ll
new file mode 100644
index 000000000000..1d1aa8747971
--- /dev/null
+++ b/llvm/test/Transforms/PGOProfile/musttail_pgo-instr-use.ll
@@ -0,0 +1,12 @@
+; RUN: llvm-profdata merge %S/Inputs/musttail_pgo-instr-use.proftext -o %t.profdata
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S
+
+declare ptr @bar()
+
+define ptr @foo() {
+entry:
+ ret ptr null
+
+2:
+ ret ptr null
+}
```
we get an error:
```
clang++: ../../llvm/include/llvm/ADT/DenseMap.h:1245: pointer llvm::DenseMapIterator<const llvm::BasicBlock *, std::unique_ptr<(anonymous namespace)::PGOUseBBInfo>, llvm::DenseMapInfo<const llvm::BasicBlock *>, llvm::detail::DenseMapPair<const llvm::BasicBlock *, std::unique_ptr<(anonymous namespace)::PGOUseBBInfo>>, true>::operator->() const [KeyT = const llvm::BasicBlock *, V
alueT = std::unique_ptr<(anonymous namespace)::PGOUseBBInfo>, KeyInfoT = llvm::DenseMapInfo<const llvm::BasicBlock *>, Bucket = llvm::detail::DenseMapPair<const llvm::BasicBlock *, std::uniq
ue_ptr<(anonymous namespace)::PGOUseBBInfo>>, IsConst = true]: Assertion `Ptr != End && "dereferencing end() iterator"' failed.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Vm9zm7gT_jTrNxoYSYAxL_wC2yU_T-fXeNqkbzsCFlsXWeIkkTbf_kbgxHGvfy7X9DweBrTPPqx2n9UinJN7jbiEbAXZZiYGfzB2KXCohb5zs9q0D0uY09Oflq3sOhJFe-mJAF4pdX8EXnl0Hnh1Y4V2nbFHB7zaXV3vrOmkQuDVVveDD6vHwXkvpPrU700ktfM2GhzGvTWdxy-e1L-BFGip8TMJXuRoWiSM0nmaAi2lbvELoc9-cVzUyPK0qxNeN0DLKIoI8KrFe-CVHpQCWgJfTf_fFS6kFFJKIgp8TQnwFQO-Lsi0_BhAQrbvicJ7VGQbSIYjai-8NJpUSuxPsKSUdrrtjDm7VoNuyP-EO0BSTqt5yvmcpWxRzOcFXRQ8P6PfDUeyNoP2aN2TAzvbTzbyUagBLxH_UjDfyZFSL0r5d1leJgnWMiEWeZoXOXtVSfwovm9qgPFLESQr8v72HSQlCa-MgoRa4QU5ot0jAZ59eEnzRSa4-PiR5m8vMb0nkKwDypGoF86Fam8u6EgUHsPWx3CkwmjcbbK54CbRhxP9eG2xUcIi6b0NO6yFBb4AXlxiOqmfIEHOI4RAfgKg9vbhSX2EWPQj-lmNxiv_MSbfhJtnhx7Q8jOSPXoiNEFrjT0RXMIaJfT-JISkJHEMvBovJzlI3aihxfNCubkBXm1QO_y_6OPQi4ynWXDujRw7akQmJSTlI2zr0QofQlg3Rjv_DLISTjYrZZo7ArwEvibOt5Np0PLPAT_1PvgBXwht9MPRDI5ocUTXiwZDtkfs7ur61uFqtdWdgeRN4PlGGKPxZyF87d1i0N8l007I_3AzU0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