[flang-commits] [flang] 93f4249 - [flang] Extend ProvenanceRange::Suffix() to handle crash case

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Mar 2 15:24:43 PST 2022


Author: Peter Klausler
Date: 2022-03-02T15:24:35-08:00
New Revision: 93f42491a54cd30b6b873f6818ea39f282e8ef6c

URL: https://github.com/llvm/llvm-project/commit/93f42491a54cd30b6b873f6818ea39f282e8ef6c
DIFF: https://github.com/llvm/llvm-project/commit/93f42491a54cd30b6b873f6818ea39f282e8ef6c.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
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 @@ 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};
   }
 


        


More information about the flang-commits mailing list