[flang-commits] [flang] a1db3e6 - [flang][runtime] Catch infinite unlimited format repetition better

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Mar 10 09:35:33 PST 2023


Author: Peter Klausler
Date: 2023-03-10T09:35:28-08:00
New Revision: a1db3e6274cfbf3e5d22de0826384c8ecab84441

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

LOG: [flang][runtime] Catch infinite unlimited format repetition better

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.

Differential Revision: https://reviews.llvm.org/D145745

Added: 
    

Modified: 
    flang/runtime/format-implementation.h

Removed: 
    


################################################################################
diff  --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h
index 275cbab2258b0..630fbf68082e4 100644
--- a/flang/runtime/format-implementation.h
+++ b/flang/runtime/format-implementation.h
@@ -212,7 +212,7 @@ static void HandleControl(CONTEXT &context, char ch, char next, int n) {
 // 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 @@ int FormatControl<CONTEXT>::CueUpNextDataEdit(Context &context, bool stop) {
       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 @@ int FormatControl<CONTEXT>::CueUpNextDataEdit(Context &context, bool stop) {
               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;


        


More information about the flang-commits mailing list