https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/229550
>From 1df15f6a3e860e1067631c1f25948b635fd636bc Mon Sep 17 00:00:00 2001 From: Anonmiraj <[email protected]> Date: Sun, 4 Oct 2026 21:24:36 +0300 Subject: [PATCH] [clang] Reuse the PresumedLoc setLocation already computed --- clang/lib/CodeGen/CGDebugInfo.cpp | 17 ++++++++++++----- clang/lib/CodeGen/CGDebugInfo.h | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 436a949891793c..dad2773e9beb1f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -360,7 +360,7 @@ void CGDebugInfo::setLocation(SourceLocation Loc) { CurLocLine = PCLoc.getLine(); if (CGM.getCodeGenOpts().DebugColumnInfo) CurLocColumn = PCLoc.getColumn(); - CurLocFile = getOrCreateFile(CurLoc); + CurLocFile = getOrCreateFile(CurLoc, PCLoc); } // If we've changed files in the middle of a lexical scope go ahead @@ -577,6 +577,17 @@ std::optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM, } llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { + if (Loc.isInvalid()) + return getOrCreateFile(Loc, PresumedLoc()); + + if (Loc == CurLoc && CurLocFile) + return CurLocFile; + return getOrCreateFile( + Loc, CGM.getContext().getSourceManager().getPresumedLoc(Loc)); +} + +llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc, + const PresumedLoc &PLoc) { SourceManager &SM = CGM.getContext().getSourceManager(); StringRef FileName; FileID FID; @@ -589,10 +600,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { FileName = TheCU->getFile()->getFilename(); CSInfo = TheCU->getFile()->getChecksum(); } else { - if (Loc == CurLoc && CurLocFile) - return CurLocFile; - - PresumedLoc PLoc = SM.getPresumedLoc(Loc); FileName = PLoc.getFilename(); if (FileName.empty()) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index b70671821c920f..cfc525143ebd98 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -783,6 +783,10 @@ class CGDebugInfo { /// location. llvm::DIFile *getOrCreateFile(SourceLocation Loc); + /// Same as above, for a Loc whose presumed location \p PLoc the caller has + /// already computed. + llvm::DIFile *getOrCreateFile(SourceLocation Loc, const PresumedLoc &PLoc); + /// Create a file debug info descriptor for a source file. llvm::DIFile * createFile(StringRef FileName, _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
