[flang-commits] [flang] a6569e5 - [flang] Don't mistakenly tokenize a Hollerith literal from "DO 100 H=..." (bug #58732)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue May 16 09:56:36 PDT 2023


Author: Peter Klausler
Date: 2023-05-16T09:56:22-07:00
New Revision: a6569e578eb4b54d48af53282d176e227f36f05d

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

LOG: [flang] Don't mistakenly tokenize a Hollerith literal from "DO 100 H=..." (bug #58732)

After tokenizing an identifier, don't allow the next token to be a
Hollerith literal.

Fixes https://github.com/llvm/llvm-project/issues/58732.

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

Added: 
    flang/test/Parser/do100h.f

Modified: 
    flang/lib/Parser/prescan.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index be5e6037cac31..19a70f1f6e06c 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -594,13 +594,18 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
     }
     preventHollerith_ = false;
   } else if (IsLegalInIdentifier(*at_)) {
-    do {
-    } while (IsLegalInIdentifier(EmitCharAndAdvance(tokens, *at_)));
+    while (IsLegalInIdentifier(EmitCharAndAdvance(tokens, *at_))) {
+    }
+    if (InFixedFormSource()) {
+      SkipSpaces();
+    }
     if ((*at_ == '\'' || *at_ == '"') &&
         tokens.CharAt(tokens.SizeInChars() - 1) == '_') { // kind_"..."
       QuotedCharacterLiteral(tokens, start);
+      preventHollerith_ = false;
+    } else {
+      preventHollerith_ = true; // DO 10 H = ...
     }
-    preventHollerith_ = false;
   } else if (*at_ == '*') {
     if (EmitCharAndAdvance(tokens, '*') == '*') {
       EmitCharAndAdvance(tokens, '*');

diff  --git a/flang/test/Parser/do100h.f b/flang/test/Parser/do100h.f
new file mode 100644
index 0000000000000..8fac8e97cb502
--- /dev/null
+++ b/flang/test/Parser/do100h.f
@@ -0,0 +1,7 @@
+! RUN: %flang_fc1 -E %s | FileCheck %s
+! Test that Hollerith is not mistakenly tokenized here
+!CHECK: do 100 h=1,10
+      do 100 h=1,10
+100   continue
+      end
+


        


More information about the flang-commits mailing list