[llvm] [DebugInfo] Handle followup loop metadata in updateLoopMetadataDebugLocations (PR #157557)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 06:55:18 PDT 2025


================
@@ -375,6 +375,32 @@ bool DebugInfoFinder::addScope(DIScope *Scope) {
   return true;
 }
 
+// Recursively handle DILocations in followup metadata etc.
+static Metadata *updateLoopMetadataDebugLocationsRecursive(
+    Metadata *MetadataIn, function_ref<Metadata *(Metadata *)> Updater) {
+  const MDNode *M = dyn_cast_or_null<MDNode>(MetadataIn);
+  // The loop metadata options should start with a MDString.
+  if (!M || M->getNumOperands() < 1 || !isa<MDString>(M->getOperand(0)))
+    return nullptr;
+
+  bool Updated = false;
+  SmallVector<Metadata *, 4> MDs{M->getOperand(0)};
+  for (Metadata *MD : llvm::drop_begin(M->operands())) {
+    if (!MD) {
+      MDs.push_back(nullptr);
+    } else if (Metadata *NewMD =
+                   updateLoopMetadataDebugLocationsRecursive(MD, Updater)) {
+      MDs.push_back(NewMD);
+      Updated = true;
+    } else if (Metadata *NewMD = Updater(MD)) {
----------------
bjope wrote:

Nice find. This was fixed in the latest update of the PR.

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


More information about the llvm-commits mailing list