Skip to content

Commit fd07a2a

Browse files
committed
DwarfDebug: Avoid creating new DebugLocs in the backend
Don't use `DebugLoc::getFnDebugLoc()`, which creates new `MDLocation`s, in the backend. We just want to grab the subprogram here anyway. llvm-svn: 233601
1 parent c02e858 commit fd07a2a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,12 @@ class MDLocalScope : public MDScope {
889889
~MDLocalScope() {}
890890

891891
public:
892+
/// \brief Get the subprogram for this scope.
893+
///
894+
/// Return this if it's an \a MDSubprogram; otherwise, look up the scope
895+
/// chain.
896+
MDSubprogram *getSubprogram() const;
897+
892898
static bool classof(const Metadata *MD) {
893899
return MD->getMetadataID() == MDSubprogramKind ||
894900
MD->getMetadataID() == MDLexicalBlockKind ||

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,13 +1168,11 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
11681168

11691169
// Record beginning of function.
11701170
PrologEndLoc = findPrologueEndLoc(MF);
1171-
if (PrologEndLoc) {
1172-
DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc();
1173-
1171+
if (MDLocation *L = PrologEndLoc) {
11741172
// We'd like to list the prologue as "not statements" but GDB behaves
11751173
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
1176-
recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(),
1177-
FnStartDL.getScope(), DWARF2_FLAG_IS_STMT);
1174+
auto *SP = L->getInlinedAtScope()->getSubprogram();
1175+
recordSourceLine(SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT);
11781176
}
11791177
}
11801178

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ MDCompileUnit *MDCompileUnit::getImpl(
238238
(SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind), Ops);
239239
}
240240

241+
MDSubprogram *MDLocalScope::getSubprogram() const {
242+
if (auto *Block = dyn_cast<MDLexicalBlockBase>(this))
243+
return Block->getScope()->getSubprogram();
244+
return const_cast<MDSubprogram *>(cast<MDSubprogram>(this));
245+
}
246+
241247
MDSubprogram *MDSubprogram::getImpl(
242248
LLVMContext &Context, Metadata *Scope, MDString *Name,
243249
MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,

0 commit comments

Comments
 (0)