[llvm] [DLCov][NFC] Propagate annotated DebugLocs through transformations (PR #138047)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Wed May 28 04:05:47 PDT 2025


================
@@ -61,19 +61,12 @@ Type *IRBuilderBase::getCurrentFunctionReturnType() const {
   return BB->getParent()->getReturnType();
 }
 
-DebugLoc IRBuilderBase::getCurrentDebugLocation() const {
-  for (auto &KV : MetadataToCopy)
-    if (KV.first == LLVMContext::MD_dbg)
-      return {cast<DILocation>(KV.second)};
-
-  return {};
-}
+DebugLoc IRBuilderBase::getCurrentDebugLocation() const { return StoredDL; }
 void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
-  for (const auto &KV : MetadataToCopy)
-    if (KV.first == LLVMContext::MD_dbg) {
-      I->setDebugLoc(DebugLoc(KV.second));
-      return;
-    }
+  // We prefer to set our current debug location if any has been set, but if
+  // our debug location is empty and I has a valid location, we shouldn't
+  // overwrite it.
+  I->setDebugLoc(StoredDL.orElse(I->getDebugLoc()));
----------------
SLTozer wrote:

It shouldn't - the existing logic says, "if we have a non-null `MD_dbg` metadata set in the IRBuilder, set that metadata on `I`, overwriting any existing metadata". The new logic says, "set `I`'s DebugLoc to `IRBuilder->StoredDL ? IRBuilder->StoredDL : I->getDebugLoc()`, which should mean exactly the same thing.

https://github.com/llvm/llvm-project/pull/138047


More information about the llvm-commits mailing list