@@ -295,22 +295,20 @@ class CoverageMappingBuilder {
295
295
}
296
296
297
297
// / Find out where a macro is expanded. If the immediate result is a
298
- // / <scratch space>, keep looking until the result isn't. Return a pair of
299
- // / \c SourceLocation. The first object is always the begin sloc of found
300
- // / result. The second should be checked by the caller: if it has value, it's
301
- // / the end sloc of the found result. Otherwise the while loop didn't get
302
- // / executed, which means the location wasn't changed and the caller has to
303
- // / learn the end sloc from somewhere else.
304
- std::pair<SourceLocation, std::optional<SourceLocation>>
305
- getNonScratchExpansionLoc (SourceLocation Loc) {
298
+ // / <scratch space>, keep looking until the result isn't. Return the source
299
+ // / range of the found result, or std::nullopt if the while loop didn't get
300
+ // / executed, which means the location wasn't changed.
301
+ std::optional<SourceRange> getNonScratchExpansion (SourceLocation Loc) {
306
302
std::optional<SourceLocation> EndLoc = std::nullopt;
307
303
while (Loc.isMacroID () &&
308
304
SM.isWrittenInScratchSpace (SM.getSpellingLoc (Loc))) {
309
305
auto ExpansionRange = SM.getImmediateExpansionRange (Loc);
310
306
Loc = ExpansionRange.getBegin ();
311
307
EndLoc = ExpansionRange.getEnd ();
312
308
}
313
- return std::make_pair (Loc, EndLoc);
309
+ if (EndLoc.has_value ())
310
+ return SourceRange (Loc, EndLoc.value ());
311
+ return std::nullopt;
314
312
}
315
313
316
314
// / Find out where the current file is included or macro is expanded. If
@@ -323,7 +321,9 @@ class CoverageMappingBuilder {
323
321
Loc = SM.getImmediateExpansionRange (Loc).getBegin ();
324
322
if (AcceptScratch)
325
323
return Loc;
326
- return getNonScratchExpansionLoc (Loc).first ;
324
+ auto NonScratchExpansion = getNonScratchExpansion (Loc);
325
+ return NonScratchExpansion.has_value () ? NonScratchExpansion->getBegin ()
326
+ : Loc;
327
327
}
328
328
329
329
// / Return true if \c Loc is a location in a built-in macro.
@@ -371,12 +371,12 @@ class CoverageMappingBuilder {
371
371
SourceLocation Loc = Region.getBeginLoc ();
372
372
373
373
// Replace Region with its definition if it is in <scratch space>.
374
- auto NonScratchExpansionLoc = getNonScratchExpansionLoc (Loc);
375
- Loc = NonScratchExpansionLoc. first ;
376
- auto EndLoc = NonScratchExpansionLoc. second ;
377
- Region.setStartLoc (Loc);
378
- Region.setEndLoc (EndLoc. has_value () ? EndLoc. value ()
379
- : Region. getEndLoc ());
374
+ auto NonScratchExpansion = getNonScratchExpansion (Loc);
375
+ if (NonScratchExpansion. has_value ()) {
376
+ Loc = NonScratchExpansion-> getBegin () ;
377
+ Region.setStartLoc (Loc);
378
+ Region.setEndLoc (NonScratchExpansion-> getEnd ());
379
+ }
380
380
381
381
// Replace Loc with FileLoc if it is expanded with system headers.
382
382
if (!SystemHeadersCoverage && SM.isInSystemMacro (Loc)) {
0 commit comments