Skip to content

Commit

Permalink
[flang] Extend ProvenanceRange::Suffix() to handle crash case
Browse files Browse the repository at this point in the history
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
  • Loading branch information
klausler committed Mar 2, 2022
1 parent 79f8e90 commit 93f4249
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flang/include/flang/Common/interval.h
Expand Up @@ -103,7 +103,7 @@ template <typename A> class Interval {
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};
}

Expand Down

0 comments on commit 93f4249

Please sign in to comment.