https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/229550
>From bb62f5f80097a2a37d8dd1bd1f2c18146b027296 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 | 22 ++++++++++++++-------- clang/lib/CodeGen/CGDebugInfo.h | 4 ++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 93428777b9b24..0a590c08debfa 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -367,7 +367,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 @@ -584,6 +584,18 @@ std::optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM, } llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { + if (Loc.isInvalid()) + return getOrCreateFile(Loc, PresumedLoc()); + + Loc = getMacroDebugLoc(CGM, Loc); + 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; @@ -596,11 +608,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { FileName = TheCU->getFile()->getFilename(); CSInfo = TheCU->getFile()->getChecksum(); } else { - Loc = getMacroDebugLoc(CGM, Loc); - if (Loc == CurLoc && CurLocFile) - return CurLocFile; - - PresumedLoc PLoc = SM.getPresumedLoc(Loc); FileName = PLoc.getFilename(); if (FileName.empty()) { @@ -627,8 +634,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { if (CSKind) CSInfo.emplace(*CSKind, Checksum); } - return createFile(FileName, CSInfo, - getSource(SM, SM.getFileID(getMacroDebugLoc(CGM, Loc)))); + return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc))); } llvm::DIFile *CGDebugInfo::createFile( diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 37520394812b4..3e0189dd3733a 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -778,6 +778,10 @@ class CGDebugInfo { /// location. llvm::DIFile *getOrCreateFile(SourceLocation Loc); + /// Same as above, for a Loc that getMacroDebugLoc() has already been + /// applied to, and whose presumed location \p PLoc the caller has 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
