[flang-commits] [PATCH] D125054: [flang][runtime] Enforce restrictions on unlimited format repetition

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon May 9 12:52:36 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfb9ec95cf0c2: [flang][runtime] Enforce restrictions on unlimited format repetition (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125054/new/

https://reviews.llvm.org/D125054

Files:
  flang/runtime/format-implementation.h
  flang/unittests/Runtime/Format.cpp


Index: flang/unittests/Runtime/Format.cpp
===================================================================
--- flang/unittests/Runtime/Format.cpp
+++ flang/unittests/Runtime/Format.cpp
@@ -107,8 +107,7 @@
           ResultsTy{"'PI='", "F9.7", "'PI='", "F9.7", "'done'"}, 1},
       {2, "(3('PI=',F9.7,:),'tooFar')",
           ResultsTy{"'PI='", "F9.7", "'PI='", "F9.7"}, 1},
-      {2, "(*('PI=',F9.7,:),'tooFar')",
-          ResultsTy{"'PI='", "F9.7", "'PI='", "F9.7"}, 1},
+      {2, "(*('PI=',F9.7,:))", ResultsTy{"'PI='", "F9.7", "'PI='", "F9.7"}, 1},
       {1, "(3F9.7)", ResultsTy{"2*F9.7"}, 2},
   };
 
Index: flang/runtime/format-implementation.h
===================================================================
--- flang/runtime/format-implementation.h
+++ flang/runtime/format-implementation.h
@@ -207,6 +207,13 @@
             maybeReversionPoint);
         return 0;
       }
+      if (height_ != 1) {
+        ReportBadFormat(context,
+            "Invalid FORMAT: '*' must be nested in exactly one set of "
+            "parentheses",
+            maybeReversionPoint);
+        return 0;
+      }
     }
     ch = Capitalize(ch);
     if (ch == '(') {
@@ -251,12 +258,20 @@
         ++restart;
       }
       if (stack_[height_ - 1].remaining == Iteration::unlimited) {
-        offset_ = restart;
+        if (height_ > 1 && GetNextChar(context) != ')') {
+          ReportBadFormat(context,
+              "Unlimited repetition in FORMAT may not be followed by more "
+              "items",
+              restart);
+          return 0;
+        }
         if (offset_ == unlimitedLoopCheck) {
           ReportBadFormat(context,
               "Unlimited repetition in FORMAT lacks data edit descriptors",
               restart);
+          return 0;
         }
+        offset_ = restart;
       } else if (stack_[height_ - 1].remaining-- > 0) {
         offset_ = restart;
       } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125054.428175.patch
Type: text/x-patch
Size: 1922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220509/3b684ba2/attachment.bin>


More information about the flang-commits mailing list