Author: Sergej Salnikov Date: 2025-11-06T11:59:01-05:00 New Revision: 6ac458527d88f480be9eee4147fab7469fad7f52
URL: https://github.com/llvm/llvm-project/commit/6ac458527d88f480be9eee4147fab7469fad7f52 DIFF: https://github.com/llvm/llvm-project/commit/6ac458527d88f480be9eee4147fab7469fad7f52.diff LOG: [clang][AST] Do not try to handle irrelevant cases in writeBareSourceLocation (#166588) `writeBareSourceLocation` is always called on either `Expanded` or `Spelling` location, in any on those cases the `SM.getSpellingLineNumber(Loc) == SM.getExpansionLineNumber(Loc) == SM.getLineNumber(Loc)`. Added: Modified: clang/include/clang/AST/JSONNodeDumper.h clang/lib/AST/JSONNodeDumper.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h index 427a9c51ece1b..d364795a05811 100644 --- a/clang/include/clang/AST/JSONNodeDumper.h +++ b/clang/include/clang/AST/JSONNodeDumper.h @@ -149,7 +149,7 @@ class JSONNodeDumper void writeIncludeStack(PresumedLoc Loc, bool JustFirst = false); // Writes the attributes of a SourceLocation object without. - void writeBareSourceLocation(SourceLocation Loc, bool IsSpelling); + void writeBareSourceLocation(SourceLocation Loc); // Writes the attributes of a SourceLocation to JSON based on its presumed // spelling location. If the given location represents a macro invocation, diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index 9f4dba9f14fa6..89abf888cbbba 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -272,15 +272,13 @@ void JSONNodeDumper::writeIncludeStack(PresumedLoc Loc, bool JustFirst) { JOS.attributeEnd(); } -void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc, - bool IsSpelling) { +void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc) { PresumedLoc Presumed = SM.getPresumedLoc(Loc); - unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc) - : SM.getExpansionLineNumber(Loc); - StringRef ActualFile = SM.getBufferName(Loc); - if (Presumed.isValid()) { - JOS.attribute("offset", SM.getDecomposedLoc(Loc).second); + StringRef ActualFile = SM.getBufferName(Loc); + auto [FID, FilePos] = SM.getDecomposedLoc(Loc); + unsigned ActualLine = SM.getLineNumber(FID, FilePos); + JOS.attribute("offset", FilePos); if (LastLocFilename != ActualFile) { JOS.attribute("file", ActualFile); JOS.attribute("line", ActualLine); @@ -318,18 +316,17 @@ void JSONNodeDumper::writeSourceLocation(SourceLocation Loc) { if (Expansion != Spelling) { // If the expansion and the spelling are diff erent, output subobjects // describing both locations. - JOS.attributeObject("spellingLoc", [Spelling, this] { - writeBareSourceLocation(Spelling, /*IsSpelling*/ true); - }); + JOS.attributeObject( + "spellingLoc", [Spelling, this] { writeBareSourceLocation(Spelling); }); JOS.attributeObject("expansionLoc", [Expansion, Loc, this] { - writeBareSourceLocation(Expansion, /*IsSpelling*/ false); + writeBareSourceLocation(Expansion); // If there is a macro expansion, add extra information if the interesting // bit is the macro arg expansion. if (SM.isMacroArgExpansion(Loc)) JOS.attribute("isMacroArgExpansion", true); }); } else - writeBareSourceLocation(Spelling, /*IsSpelling*/ true); + writeBareSourceLocation(Spelling); } void JSONNodeDumper::writeSourceRange(SourceRange R) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
