[flang] Extend ProvenanceRange::Suffix() to handle crash case

Suffix() can be called from AllSources::IntersectionWithSourceFiles()
when a contiguous range of source provenance overlaps a macro expansion.
It skips over the macro expansion and recurses on the remainder of
the range, which might end with a bit that does overlap with a
source file.  However, in the case where the original range is
entirely within the expanded macro, Suffix() crashes when called
with a skip offset greater than the size of the range.

Rather than add logic around this and other calls to Suffix() to
avoid passing an out-of-range skip, it's better to accommodate it
in Suffix() and return an empty result.

Differential Revision: https://reviews.llvm.org/D120843
This commit is contained in:
Peter Klausler 2022-02-18 10:17:04 -08:00
parent 79f8e909ed
commit 93f42491a5
1 changed files with 1 additions and 1 deletions

View File

@ -103,7 +103,7 @@ public:
return {start_, std::min(size_, n)};
}
Interval Suffix(std::size_t n) const {
CHECK(n <= size_);
n = std::min(n, size_);
return {start_ + n, size_ - n};
}