Skip to content

Commit 108a9ac

Browse files
committed
Revert "address comments: return optional<SourceRange>; update region only when needed"
This reverts commit 0eeb0d3e392b1ea1ae47bc8c977eb709cd1c264c.
1 parent 14e52c3 commit 108a9ac

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,22 @@ class CoverageMappingBuilder {
295295
}
296296

297297
/// Find out where a macro is expanded. If the immediate result is a
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) {
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) {
302306
std::optional<SourceLocation> EndLoc = std::nullopt;
303307
while (Loc.isMacroID() &&
304308
SM.isWrittenInScratchSpace(SM.getSpellingLoc(Loc))) {
305309
auto ExpansionRange = SM.getImmediateExpansionRange(Loc);
306310
Loc = ExpansionRange.getBegin();
307311
EndLoc = ExpansionRange.getEnd();
308312
}
309-
if (EndLoc.has_value())
310-
return SourceRange(Loc, EndLoc.value());
311-
return std::nullopt;
313+
return std::make_pair(Loc, EndLoc);
312314
}
313315

314316
/// Find out where the current file is included or macro is expanded. If
@@ -321,9 +323,7 @@ class CoverageMappingBuilder {
321323
Loc = SM.getImmediateExpansionRange(Loc).getBegin();
322324
if (AcceptScratch)
323325
return Loc;
324-
auto NonScratchExpansion = getNonScratchExpansion(Loc);
325-
return NonScratchExpansion.has_value() ? NonScratchExpansion->getBegin()
326-
: Loc;
326+
return getNonScratchExpansionLoc(Loc).first;
327327
}
328328

329329
/// Return true if \c Loc is a location in a built-in macro.
@@ -371,12 +371,12 @@ class CoverageMappingBuilder {
371371
SourceLocation Loc = Region.getBeginLoc();
372372

373373
// Replace Region with its definition if it is in <scratch space>.
374-
auto NonScratchExpansion = getNonScratchExpansion(Loc);
375-
if (NonScratchExpansion.has_value()) {
376-
Loc = NonScratchExpansion->getBegin();
377-
Region.setStartLoc(Loc);
378-
Region.setEndLoc(NonScratchExpansion->getEnd());
379-
}
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());
380380

381381
// Replace Loc with FileLoc if it is expanded with system headers.
382382
if (!SystemHeadersCoverage && SM.isInSystemMacro(Loc)) {

0 commit comments

Comments
 (0)