From 829365aeef9cde27b00969e7801b0f4844025ca1 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 11 Feb 2016 19:41:47 +0000 Subject: [PATCH] [codeview] Fix bug around multi-level wrapper inlining If there were wrapper functions with no instructions of their own in the inlining tree, we would fail to emit InlineSite records for them. llvm-svn: 260571 --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 33 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 5473228..4817729 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -117,6 +117,13 @@ CodeViewDebug::InlineSite &CodeViewDebug::getInlineSite(const DILocation *Loc) { return *Site; } +static void addLocIfNotPresent(SmallVectorImpl &Locs, + const DILocation *Loc) { + auto B = Locs.begin(), E = Locs.end(); + if (std::find(B, E, Loc) == E) + Locs.push_back(Loc); +} + void CodeViewDebug::maybeRecordLocation(DebugLoc DL, const MachineFunction *MF) { // Skip this instruction if it has the same location as the previous one. @@ -147,24 +154,24 @@ void CodeViewDebug::maybeRecordLocation(DebugLoc DL, CurFn->LastLoc = DL; unsigned FuncId = CurFn->FuncId; - if (const DILocation *Loc = DL->getInlinedAt()) { + if (DL->getInlinedAt()) { + const DILocation *Loc = DL.get(); + // If this location was actually inlined from somewhere else, give it the ID // of the inline call site. - FuncId = getInlineSite(DL.get()).SiteFuncId; - CurFn->ChildSites.push_back(Loc); + FuncId = getInlineSite(Loc).SiteFuncId; + // Ensure we have links in the tree of inline call sites. - const DILocation *ChildLoc = nullptr; - while (Loc->getInlinedAt()) { + const DILocation *SiteLoc; + bool FirstLoc = true; + while ((SiteLoc = Loc->getInlinedAt())) { InlineSite &Site = getInlineSite(Loc); - if (ChildLoc) { - // Record the child inline site if not already present. - auto B = Site.ChildSites.begin(), E = Site.ChildSites.end(); - if (std::find(B, E, Loc) != E) - break; - Site.ChildSites.push_back(Loc); - } - ChildLoc = Loc; + if (!FirstLoc) + addLocIfNotPresent(Site.ChildSites, Loc); + FirstLoc = false; + Loc = SiteLoc; } + addLocIfNotPresent(CurFn->ChildSites, Loc); } OS.EmitCVLocDirective(FuncId, FileId, DL.getLine(), DL.getCol(), -- 2.7.4