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

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu May 11 16:04:48 PDT 2023


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

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

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


https://reviews.llvm.org/D150406

Files:
  flang/lib/Parser/prescan.cpp
  flang/test/Parser/do100h.f


Index: flang/test/Parser/do100h.f
===================================================================
--- /dev/null
+++ 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
+
Index: flang/lib/Parser/prescan.cpp
===================================================================
--- flang/lib/Parser/prescan.cpp
+++ flang/lib/Parser/prescan.cpp
@@ -594,13 +594,18 @@
     }
     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, '*');


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150406.521493.patch
Type: text/x-patch
Size: 1240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230511/55fa937a/attachment-0001.bin>


More information about the flang-commits mailing list