diff options
author | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2024-08-29 14:12:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-29 14:12:02 +0100 |
commit | 43661a1214353ea1773a711f403f8d1118e9ca0f (patch) | |
tree | 31853700ee4b5e60a8d1755ffcbff74c8a2b1e35 /llvm/lib/IR/BasicBlock.cpp | |
parent | ba52a09abe3f3a2323dd7df3fe1739630e054077 (diff) | |
download | llvm-43661a1214353ea1773a711f403f8d1118e9ca0f.zip llvm-43661a1214353ea1773a711f403f8d1118e9ca0f.tar.gz llvm-43661a1214353ea1773a711f403f8d1118e9ca0f.tar.bz2 |
[RemoveDIs] Fix spliceDebugInfo splice-to-end edge case (#105671)
Fix #105571 which demonstrates an end() iterator dereference when
performing a non-empty splice to end() from a region that ends at
Src::end().
Rather than calling Instruction::adoptDbgRecords from Dest, create a marker
(which takes an iterator) and absorbDebugValues onto that. The "absorb" variant
doesn't clean up the source marker, which in this case we know is a trailing
marker, so we have to do that manually.
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r-- | llvm/lib/IR/BasicBlock.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index e259ec5..39cefa5 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -975,8 +975,16 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src, if (ReadFromTail && Src->getMarker(Last)) { DbgMarker *FromLast = Src->getMarker(Last); if (LastIsEnd) { - Dest->adoptDbgRecords(Src, Last, true); - // adoptDbgRecords will release any trailers. + if (Dest == end()) { + // Abosrb the trailing markers from Src. + assert(FromLast == Src->getTrailingDbgRecords()); + createMarker(Dest)->absorbDebugValues(*FromLast, true); + FromLast->eraseFromParent(); + Src->deleteTrailingDbgRecords(); + } else { + // adoptDbgRecords will release any trailers. + Dest->adoptDbgRecords(Src, Last, true); + } assert(!Src->getTrailingDbgRecords()); } else { // FIXME: can we use adoptDbgRecords here to reduce allocations? |