[PATCH] D86185: [Cloning] Fix to cloning DISubprograms.

Amy Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 18:06:26 PDT 2020


akhuang created this revision.
akhuang added reviewers: aprantl, dblaikie, loladiro.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
akhuang requested review of this revision.

When trying to enable -debug-info-kind=constructor there was an assert
that occurs during debug info cloning ("mismatched subprogram between
llvm.dbg.value variable and !dbg attachment").
It appears that during llvm::CloneFunctionInto, a DISubprogram could be
duplicated when MapMetadata is called, and then added to the MD map again
when DIFinder gets a list of subprograms. This results in two different
versions of the DISubprogram.

This patch switches the order so that the DIFinder subprograms are
added before MapMetadata is called.

I'm not sure how to create a small IR testcase for this; there's a long-ish
c++ repro in the bug.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46784


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86185

Files:
  llvm/lib/Transforms/Utils/CloneFunction.cpp


Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -137,16 +137,6 @@
       MD[SP].reset(SP);
   }
 
-  SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
-  OldFunc->getAllMetadata(MDs);
-  for (auto MD : MDs) {
-    NewFunc->addMetadata(
-        MD.first,
-        *MapMetadata(MD.second, VMap,
-                     ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
-                     TypeMapper, Materializer));
-  }
-
   // Everything else beyond this point deals with function instructions,
   // so if we are dealing with a function declaration, we're done.
   if (OldFunc->isDeclaration())
@@ -201,6 +191,16 @@
   for (DIType *Type : DIFinder.types())
     VMap.MD()[Type].reset(Type);
 
+  SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
+  OldFunc->getAllMetadata(MDs);
+  for (auto MD : MDs) {
+    NewFunc->addMetadata(
+        MD.first,
+        *MapMetadata(MD.second, VMap,
+                     ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
+                     TypeMapper, Materializer));
+  }
+
   // Loop over all of the instructions in the function, fixing up operand
   // references as we go.  This uses VMap to do all the hard work.
   for (Function::iterator BB =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86185.286446.patch
Type: text/x-patch
Size: 1380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200819/4758ed4f/attachment.bin>


More information about the llvm-commits mailing list