================ @@ -292,10 +292,22 @@ class CoverageMappingBuilder { return SM.getLocForEndOfFile(SM.getFileID(Loc)); } - /// Find out where the current file is included or macro is expanded. - SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc) { - return Loc.isMacroID() ? SM.getImmediateExpansionRange(Loc).getBegin() - : SM.getIncludeLoc(SM.getFileID(Loc)); + /// Find out where the current file is included or macro is expanded. If + /// \c AcceptScratch is set to false, keep looking for expansions until the + /// found sloc is not a <scratch space> + SourceLocation getIncludeOrExpansionLoc(SourceLocation Loc, + bool AcceptScratch = true) { + if (Loc.isMacroID()) { + Loc = SM.getImmediateExpansionRange(Loc).getBegin(); + if (!AcceptScratch) + while (Loc.isMacroID() && + SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) { + auto ExpansionRange = SM.getImmediateExpansionRange(Loc); + Loc = ExpansionRange.getBegin(); + } + } else + Loc = SM.getIncludeLoc(SM.getFileID(Loc)); ---------------- chapuni wrote:
We prefer early return. ``` if (!Loc.isMacroID()) return SM.getIncludeLoc(...); Loc = ...; if (AcceptScratch) return Loc; while (...) ... ``` ``` https://github.com/llvm/llvm-project/pull/89869 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits