[flang-commits] [PATCH] D145745: [flang][runtime] Catch infinite unlimited format repetition better

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Mar 9 16:31:32 PST 2023


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

The runtime check for infinite unlimited format repetition is missing
the case of implicit unlimited format repetition at the top level  
without finding the next data edit descriptor that corresponds with
a data list item.

Replace the check with a Boolean flag that detects unlimited   
repetition hitting a right parenthesis and restarting, and fail
when it happens the second time.


https://reviews.llvm.org/D145745

Files:
  flang/runtime/format-implementation.h


Index: flang/runtime/format-implementation.h
===================================================================
--- flang/runtime/format-implementation.h
+++ flang/runtime/format-implementation.h
@@ -212,7 +212,7 @@
 // format validator gauntlet.
 template <typename CONTEXT>
 int FormatControl<CONTEXT>::CueUpNextDataEdit(Context &context, bool stop) {
-  int unlimitedLoopCheck{-1};
+  bool hitUnlimitedLoopEnd{false};
   // Do repetitions remain on an unparenthesized data edit?
   while (height_ > 1 && format_[stack_[height_ - 1].start] != '(') {
     offset_ = stack_[height_ - 1].start;
@@ -267,7 +267,6 @@
       RUNTIME_CHECK(context, format_[stack_[height_].start] == '(');
       if (unlimited || height_ == 0) {
         stack_[height_].remaining = Iteration::unlimited;
-        unlimitedLoopCheck = offset_ - 1;
       } else if (repeat) {
         if (*repeat <= 0) {
           *repeat = 1; // error recovery
@@ -305,12 +304,13 @@
               restart);
           return 0;
         }
-        if (offset_ == unlimitedLoopCheck) {
+        if (hitUnlimitedLoopEnd) {
           ReportBadFormat(context,
               "Unlimited repetition in FORMAT lacks data edit descriptors",
               restart);
           return 0;
         }
+        hitUnlimitedLoopEnd = true;
         offset_ = restart;
       } else if (stack_[height_ - 1].remaining-- > 0) {
         offset_ = restart;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145745.503970.patch
Type: text/x-patch
Size: 1407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230310/860256bb/attachment-0001.bin>


More information about the flang-commits mailing list