[flang-commits] [PATCH] D120843: [flang] Extend ProvenanceRange::Suffix() to handle crash case

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 2 13:11:07 PST 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D120843

Files:
  flang/include/flang/Common/interval.h


Index: flang/include/flang/Common/interval.h
===================================================================
--- flang/include/flang/Common/interval.h
+++ flang/include/flang/Common/interval.h
@@ -103,7 +103,7 @@
     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};
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120843.412521.patch
Type: text/x-patch
Size: 403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220302/d2abf336/attachment.bin>


More information about the flang-commits mailing list