[clang] [Coverage][Expansion] handle nested macros in scratch space (PR #89869)

NAKAMURA Takumi via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 15:31:33 PDT 2024


================
@@ -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 a pair of
+  /// \c SourceLocation. The first object is always the begin sloc of found
+  /// result. The second should be checked by the caller: if it has value, it's
+  /// the end sloc of the found result. Otherwise the while loop didn't get
+  /// executed, which means the location wasn't changed and the caller has to
+  /// learn the end sloc from somewhere else.
+  std::pair<SourceLocation, std::optional<SourceLocation>>
----------------
chapuni wrote:

Could it return `optional<SourceRange>`?

https://github.com/llvm/llvm-project/pull/89869


More information about the cfe-commits mailing list