================ @@ -292,10 +292,36 @@ 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 a macro is expanded. If the immediate result is a + /// <scratch space>, keep looking until the result isn't. Return the source + /// range of the found result, or std::nullopt if the while loop didn't get + /// executed, which means the location wasn't changed. + std::optional<SourceRange> getNonScratchExpansion(SourceLocation Loc) { + std::optional<SourceLocation> EndLoc = std::nullopt; + while (Loc.isMacroID() && + SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) { + auto ExpansionRange = SM.getImmediateExpansionRange(Loc); + Loc = ExpansionRange.getBegin(); + EndLoc = ExpansionRange.getEnd(); + } + if (EndLoc.has_value()) + return SourceRange(Loc, EndLoc.value()); ---------------- chapuni wrote:
I meant; ``` auto getNonScratchExpansionLoc(SourceLocation Loc) { std::optional<CharSourceRange> ExpansionRange = std::nullopt; while (Loc.isMacroID() && SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) { ExpansionRange = SM.getImmediateExpansionRange(Loc); Loc = ExpansionRange->getBegin(); } return ExpansionRange; } ``` (No need to follow) 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