From 93f42491a54cd30b6b873f6818ea39f282e8ef6c Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 18 Feb 2022 10:17:04 -0800 Subject: [PATCH] [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 --- flang/include/flang/Common/interval.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/include/flang/Common/interval.h b/flang/include/flang/Common/interval.h index 9d819f036491..c4cab0ccf113 100644 --- a/flang/include/flang/Common/interval.h +++ b/flang/include/flang/Common/interval.h @@ -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}; }