<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Keno,<div class=""><br class=""></div><div class="">This breaks some internal builds.</div><div class="">We basically hit this assertion:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Assertion failed: (!MustCloneSP || ModuleLevelChanges), function CloneFunctionInto, file lib/Transforms/Utils/CloneFunction.cpp, line 130.</span></div></div><div class=""><br class=""></div><div class="">Our invocation looks like this:</div><div class=""><div class=""><font face="Menlo" class="">CloneFunctionInto(NewFunc, F, VMap, /*ModuleLevelChanges=*/false, </font><span style="font-family: Menlo;" class="">Returns);</span></div></div><div class=""><br class=""></div><div class="">Could you advise on how we should fix this?</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">-Quentin</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 1, 2017, at 4:02 PM, Keno Fischer via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: kfischer<br class="">Date: Thu Jun  1 18:02:12 2017<br class="">New Revision: 304488<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=304488&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=304488&view=rev</a><br class="">Log:<br class="">Reapply "[Cloning] Take another pass at properly cloning debug info"<br class=""><br class="">This was rL304226, reverted in 304228 due to a clang assertion failure<br class="">on the build bots. That problem should have been addressed by clang<br class="">commit rL304470.<br class=""><br class="">Modified:<br class="">    llvm/trunk/include/llvm/IR/DebugLoc.h<br class="">    llvm/trunk/include/llvm/Transforms/Utils/Cloning.h<br class="">    llvm/trunk/lib/IR/DebugLoc.cpp<br class="">    llvm/trunk/lib/Transforms/Coroutines/CoroSplit.cpp<br class="">    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp<br class="">    llvm/trunk/unittests/Transforms/Utils/Cloning.cpp<br class=""><br class="">Modified: llvm/trunk/include/llvm/IR/DebugLoc.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugLoc.h?rev=304488&r1=304487&r2=304488&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugLoc.h?rev=304488&r1=304487&r2=304488&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/IR/DebugLoc.h (original)<br class="">+++ llvm/trunk/include/llvm/IR/DebugLoc.h Thu Jun  1 18:02:12 2017<br class="">@@ -90,12 +90,6 @@ namespace llvm {<br class="">                                     DenseMap<const MDNode *, MDNode *> &Cache,<br class="">                                     bool ReplaceLast = false);<br class=""><br class="">-    /// Reparent all debug locations referenced by \c I that belong to \c OrigSP<br class="">-    /// to become (possibly indirect) children of \c NewSP.<br class="">-    static void reparentDebugInfo(Instruction &I, DISubprogram *OrigSP,<br class="">-                                  DISubprogram *NewSP,<br class="">-                                  DenseMap<const MDNode *, MDNode *> &Cache);<br class="">-<br class="">     unsigned getLine() const;<br class="">     unsigned getCol() const;<br class="">     MDNode *getScope() const;<br class=""><br class="">Modified: llvm/trunk/include/llvm/Transforms/Utils/Cloning.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Cloning.h?rev=304488&r1=304487&r2=304488&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Cloning.h?rev=304488&r1=304487&r2=304488&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Transforms/Utils/Cloning.h (original)<br class="">+++ llvm/trunk/include/llvm/Transforms/Utils/Cloning.h Thu Jun  1 18:02:12 2017<br class="">@@ -36,6 +36,7 @@ class BasicBlock;<br class=""> class BlockFrequencyInfo;<br class=""> class CallInst;<br class=""> class CallGraph;<br class="">+class DebugInfoFinder;<br class=""> class DominatorTree;<br class=""> class Function;<br class=""> class Instruction;<br class="">@@ -110,7 +111,8 @@ struct ClonedCodeInfo {<br class=""> ///<br class=""> BasicBlock *CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,<br class="">                             const Twine &NameSuffix = "", Function *F = nullptr,<br class="">-                            ClonedCodeInfo *CodeInfo = nullptr);<br class="">+                            ClonedCodeInfo *CodeInfo = nullptr,<br class="">+                            DebugInfoFinder *DIFinder = nullptr);<br class=""><br class=""> /// CloneFunction - Return a copy of the specified function and add it to that<br class=""> /// function's module.  Also, any references specified in the VMap are changed<br class=""><br class="">Modified: llvm/trunk/lib/IR/DebugLoc.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugLoc.cpp?rev=304488&r1=304487&r2=304488&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugLoc.cpp?rev=304488&r1=304487&r2=304488&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/IR/DebugLoc.cpp (original)<br class="">+++ llvm/trunk/lib/IR/DebugLoc.cpp Thu Jun  1 18:02:12 2017<br class="">@@ -99,87 +99,6 @@ DebugLoc DebugLoc::appendInlinedAt(Debug<br class="">   return Last;<br class=""> }<br class=""><br class="">-/// Reparent \c Scope from \c OrigSP to \c NewSP.<br class="">-static DIScope *reparentScope(LLVMContext &Ctx, DIScope *Scope,<br class="">-                              DISubprogram *OrigSP, DISubprogram *NewSP,<br class="">-                              DenseMap<const MDNode *, MDNode *> &Cache) {<br class="">-  SmallVector<DIScope *, 3> ScopeChain;<br class="">-  DIScope *Last = NewSP;<br class="">-  DIScope *CurScope = Scope;<br class="">-  do {<br class="">-    if (auto *SP = dyn_cast<DISubprogram>(CurScope)) {<br class="">-      // Don't rewrite this scope chain if it doesn't lead to the replaced SP.<br class="">-      if (SP != OrigSP)<br class="">-        return Scope;<br class="">-      Cache.insert({OrigSP, NewSP});<br class="">-      break;<br class="">-    }<br class="">-    if (auto *Found = Cache[CurScope]) {<br class="">-      Last = cast<DIScope>(Found);<br class="">-      break;<br class="">-    }<br class="">-    ScopeChain.push_back(CurScope);<br class="">-  } while ((CurScope = CurScope->getScope().resolve()));<br class="">-<br class="">-  // Starting from the top, rebuild the nodes to point to the new inlined-at<br class="">-  // location (then rebuilding the rest of the chain behind it) and update the<br class="">-  // map of already-constructed inlined-at nodes.<br class="">-  for (const DIScope *MD : reverse(ScopeChain)) {<br class="">-    if (auto *LB = dyn_cast<DILexicalBlock>(MD))<br class="">-      Cache[MD] = Last = DILexicalBlock::getDistinct(<br class="">-          Ctx, Last, LB->getFile(), LB->getLine(), LB->getColumn());<br class="">-    else if (auto *LB = dyn_cast<DILexicalBlockFile>(MD))<br class="">-      Cache[MD] = Last = DILexicalBlockFile::getDistinct(<br class="">-          Ctx, Last, LB->getFile(), LB->getDiscriminator());<br class="">-    else<br class="">-      llvm_unreachable("illegal parent scope");<br class="">-  }<br class="">-  return Last;<br class="">-}<br class="">-<br class="">-void DebugLoc::reparentDebugInfo(Instruction &I, DISubprogram *OrigSP,<br class="">-                                 DISubprogram *NewSP,<br class="">-                                 DenseMap<const MDNode *, MDNode *> &Cache) {<br class="">-  auto DL = I.getDebugLoc();<br class="">-  if (!OrigSP || !NewSP || OrigSP == NewSP || !DL)<br class="">-    return;<br class="">-<br class="">-  // Reparent the debug location.<br class="">-  auto &Ctx = I.getContext();<br class="">-  DILocation *InlinedAt = DL->getInlinedAt();<br class="">-  if (InlinedAt) {<br class="">-    while (auto *IA = InlinedAt->getInlinedAt())<br class="">-      InlinedAt = IA;<br class="">-    auto NewScope =<br class="">-        reparentScope(Ctx, InlinedAt->getScope(), OrigSP, NewSP, Cache);<br class="">-    InlinedAt =<br class="">-        DebugLoc::get(InlinedAt->getLine(), InlinedAt->getColumn(), NewScope);<br class="">-  }<br class="">-  I.setDebugLoc(<br class="">-      DebugLoc::get(DL.getLine(), DL.getCol(),<br class="">-                    reparentScope(Ctx, DL->getScope(), OrigSP, NewSP, Cache),<br class="">-                    DebugLoc::appendInlinedAt(DL, InlinedAt, Ctx, Cache,<br class="">-                                              ReplaceLastInlinedAt)));<br class="">-<br class="">-  // Fix up debug variables to point to NewSP.<br class="">-  auto reparentVar = [&](DILocalVariable *Var) {<br class="">-    return DILocalVariable::get(<br class="">-        Ctx,<br class="">-        cast<DILocalScope>(<br class="">-            reparentScope(Ctx, Var->getScope(), OrigSP, NewSP, Cache)),<br class="">-        Var->getName(), Var->getFile(), Var->getLine(), Var->getType(),<br class="">-        Var->getArg(), Var->getFlags(), Var->getAlignInBits());<br class="">-  };<br class="">-  if (auto *DbgValue = dyn_cast<DbgValueInst>(&I)) {<br class="">-    auto *Var = DbgValue->getVariable();<br class="">-    I.setOperand(2, MetadataAsValue::get(Ctx, reparentVar(Var)));<br class="">-  } else if (auto *DbgDeclare = dyn_cast<DbgDeclareInst>(&I)) {<br class="">-    auto *Var = DbgDeclare->getVariable();<br class="">-    I.setOperand(1, MetadataAsValue::get(Ctx, reparentVar(Var)));<br class="">-  }<br class="">-}<br class="">-<br class="">-<br class=""> #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)<br class=""> LLVM_DUMP_METHOD void DebugLoc::dump() const {<br class="">   if (!Loc)<br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Coroutines/CoroSplit.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Coroutines/CoroSplit.cpp?rev=304488&r1=304487&r2=304488&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Coroutines/CoroSplit.cpp?rev=304488&r1=304487&r2=304488&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Coroutines/CoroSplit.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Coroutines/CoroSplit.cpp Thu Jun  1 18:02:12 2017<br class="">@@ -228,7 +228,7 @@ static Function *createClone(Function &F<br class=""><br class="">   SmallVector<ReturnInst *, 4> Returns;<br class=""><br class="">-  CloneFunctionInto(NewF, &F, VMap, /*ModuleLevelChanges=*/false, Returns);<br class="">+  CloneFunctionInto(NewF, &F, VMap, /*ModuleLevelChanges=*/true, Returns);<br class=""><br class="">   // Remove old returns.<br class="">   for (ReturnInst *Return : Returns)<br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=304488&r1=304487&r2=304488&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=304488&r1=304487&r2=304488&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Thu Jun  1 18:02:12 2017<br class="">@@ -37,10 +37,10 @@<br class=""> using namespace llvm;<br class=""><br class=""> /// See comments in Cloning.h.<br class="">-BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,<br class="">-                                  ValueToValueMapTy &VMap,<br class="">+BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,<br class="">                                   const Twine &NameSuffix, Function *F,<br class="">-                                  ClonedCodeInfo *CodeInfo) {<br class="">+                                  ClonedCodeInfo *CodeInfo,<br class="">+                                  DebugInfoFinder *DIFinder) {<br class="">   DenseMap<const MDNode *, MDNode *> Cache;<br class="">   BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "", F);<br class="">   if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);<br class="">@@ -50,10 +50,11 @@ BasicBlock *llvm::CloneBasicBlock(const<br class="">   // Loop over all instructions, and copy them over.<br class="">   for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();<br class="">        II != IE; ++II) {<br class="">+<br class="">+    if (DIFinder && F->getParent() && II->getDebugLoc())<br class="">+      DIFinder->processLocation(*F->getParent(), II->getDebugLoc().get());<br class="">+<br class="">     Instruction *NewInst = II->clone();<br class="">-    if (F && F->getSubprogram())<br class="">-      DebugLoc::reparentDebugInfo(*NewInst, BB->getParent()->getSubprogram(),<br class="">-                                  F->getSubprogram(), Cache);<br class="">     if (II->hasName())<br class="">       NewInst->setName(II->getName()+NameSuffix);<br class="">     NewBB->getInstList().push_back(NewInst);<br class="">@@ -122,31 +123,38 @@ void llvm::CloneFunctionInto(Function *N<br class="">       AttributeList::get(NewFunc->getContext(), OldAttrs.getFnAttributes(),<br class="">                          OldAttrs.getRetAttributes(), NewArgAttrs));<br class=""><br class="">+  bool MustCloneSP =<br class="">+      OldFunc->getParent() && OldFunc->getParent() == NewFunc->getParent();<br class="">+  DISubprogram *SP = OldFunc->getSubprogram();<br class="">+  if (SP) {<br class="">+    assert(!MustCloneSP || ModuleLevelChanges);<br class="">+    // Add mappings for some DebugInfo nodes that we don't want duplicated<br class="">+    // even if they're distinct.<br class="">+    auto &MD = VMap.MD();<br class="">+    MD[SP->getUnit()].reset(SP->getUnit());<br class="">+    MD[SP->getType()].reset(SP->getType());<br class="">+    MD[SP->getFile()].reset(SP->getFile());<br class="">+    // If we're not cloning into the same module, no need to clone the<br class="">+    // subprogram<br class="">+    if (!MustCloneSP)<br class="">+      MD[SP].reset(SP);<br class="">+  }<br class="">+<br class="">   SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;<br class="">   OldFunc->getAllMetadata(MDs);<br class="">   for (auto MD : MDs) {<br class="">-    MDNode *NewMD;<br class="">-    bool MustCloneSP =<br class="">-        (MD.first == LLVMContext::MD_dbg && OldFunc->getParent() &&<br class="">-         OldFunc->getParent() == NewFunc->getParent());<br class="">-    if (MustCloneSP) {<br class="">-      auto *SP = cast<DISubprogram>(MD.second);<br class="">-      NewMD = DISubprogram::getDistinct(<br class="">-          NewFunc->getContext(), SP->getScope(), SP->getName(),<br class="">-          SP->getLinkageName(), SP->getFile(), SP->getLine(), SP->getType(),<br class="">-          SP->isLocalToUnit(), SP->isDefinition(), SP->getScopeLine(),<br class="">-          SP->getContainingType(), SP->getVirtuality(), SP->getVirtualIndex(),<br class="">-          SP->getThisAdjustment(), SP->getFlags(), SP->isOptimized(),<br class="">-          SP->getUnit(), SP->getTemplateParams(), SP->getDeclaration(),<br class="">-          SP->getVariables(), SP->getThrownTypes());<br class="">-    } else<br class="">-      NewMD =<br class="">-          MapMetadata(MD.second, VMap,<br class="">-                      ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,<br class="">-                      TypeMapper, Materializer);<br class="">-    NewFunc->addMetadata(MD.first, *NewMD);<br class="">+    NewFunc->addMetadata(<br class="">+        MD.first,<br class="">+        *MapMetadata(MD.second, VMap,<br class="">+                     ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,<br class="">+                     TypeMapper, Materializer));<br class="">   }<br class=""><br class="">+  // When we remap instructions, we want to avoid duplicating inlined<br class="">+  // DISubprograms, so record all subprograms we find as we duplicate<br class="">+  // instructions and then freeze them in the MD map.<br class="">+  DebugInfoFinder DIFinder;<br class="">+<br class="">   // Loop over all of the basic blocks in the function, cloning them as<br class="">   // appropriate.  Note that we save BE this way in order to handle cloning of<br class="">   // recursive functions into themselves.<br class="">@@ -156,7 +164,8 @@ void llvm::CloneFunctionInto(Function *N<br class="">     const BasicBlock &BB = *BI;<br class=""><br class="">     // Create a new basic block and copy instructions into it!<br class="">-    BasicBlock *CBB = CloneBasicBlock(&BB, VMap, NameSuffix, NewFunc, CodeInfo);<br class="">+    BasicBlock *CBB = CloneBasicBlock(&BB, VMap, NameSuffix, NewFunc, CodeInfo,<br class="">+                                      SP ? &DIFinder : nullptr);<br class=""><br class="">     // Add basic block mapping.<br class="">     VMap[&BB] = CBB;<br class="">@@ -178,6 +187,12 @@ void llvm::CloneFunctionInto(Function *N<br class="">       Returns.push_back(RI);<br class="">   }<br class=""><br class="">+  for (DISubprogram *ISP : DIFinder.subprograms()) {<br class="">+    if (ISP != SP) {<br class="">+      VMap.MD()[ISP].reset(ISP);<br class="">+    }<br class="">+  }<br class="">+<br class="">   // Loop over all of the instructions in the function, fixing up operand<br class="">   // references as we go.  This uses VMap to do all the hard work.<br class="">   for (Function::iterator BB =<br class="">@@ -226,7 +241,7 @@ Function *llvm::CloneFunction(Function *<br class="">     }<br class=""><br class="">   SmallVector<ReturnInst*, 8> Returns;  // Ignore returns cloned.<br class="">-  CloneFunctionInto(NewF, F, VMap, /*ModuleLevelChanges=*/false, Returns, "",<br class="">+  CloneFunctionInto(NewF, F, VMap, F->getSubprogram() != nullptr, Returns, "",<br class="">                     CodeInfo);<br class=""><br class="">   return NewF;<br class=""><br class="">Modified: llvm/trunk/unittests/Transforms/Utils/Cloning.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Cloning.cpp?rev=304488&r1=304487&r2=304488&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Cloning.cpp?rev=304488&r1=304487&r2=304488&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/unittests/Transforms/Utils/Cloning.cpp (original)<br class="">+++ llvm/trunk/unittests/Transforms/Utils/Cloning.cpp Thu Jun  1 18:02:12 2017<br class="">@@ -361,7 +361,7 @@ TEST_F(CloneFunc, NewFunctionCreated) {<br class=""> // Test that a new subprogram entry was added and is pointing to the new<br class=""> // function, while the original subprogram still points to the old one.<br class=""> TEST_F(CloneFunc, Subprogram) {<br class="">-  EXPECT_FALSE(verifyModule(*M));<br class="">+  EXPECT_FALSE(verifyModule(*M, &errs()));<br class="">   EXPECT_EQ(3U, Finder->subprogram_count());<br class="">   EXPECT_NE(NewFunc->getSubprogram(), OldFunc->getSubprogram());<br class=""> }<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>