[flang-commits] [PATCH] D142763: [flang] Diagnose fixed form statement that begins with continuation line

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 27 09:46:28 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.

A fixed form continuation line should not be the first line of a statement;
emit a warning if it looks like one is so that the programmer can look
for a missing card.


https://reviews.llvm.org/D142763

Files:
  flang/lib/Parser/prescan.cpp
  flang/test/Preprocessing/pp044.F


Index: flang/test/Preprocessing/pp044.F
===================================================================
--- flang/test/Preprocessing/pp044.F
+++ flang/test/Preprocessing/pp044.F
@@ -1,14 +1,15 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
 ! CHECK-NOT:z = 111
-* #define directive amid continuations
-      integer, parameter :: KWM = 222, KWM111 = 333, KWM222 = 555
-      integer, parameter :: KWMKWM = 333
+! CHECK:warning: Statement should not begin with a continuation line
+! CHECK:j=111+444
+* #define directive amid continuations.
+      integer, parameter :: KWM = 222
       integer, parameter :: z = KWM
 #define KWM 111
-     +KWM+444
-      if (z .EQ. 777) then
+     ,j=KWM+444
+      if (z .EQ. 222 .AND. j .EQ. 555) then
         print *, 'yes'
       else
-        print *, 'no', z
+        print *, 'no', z, _4
       end if
       end
Index: flang/lib/Parser/prescan.cpp
===================================================================
--- flang/lib/Parser/prescan.cpp
+++ flang/lib/Parser/prescan.cpp
@@ -269,9 +269,9 @@
 }
 
 void Prescanner::LabelField(TokenSequence &token) {
-  const char *bad{nullptr};
   int outCol{1};
   const char *start{at_};
+  std::optional<int> badColumn;
   for (; *at_ != '\n' && column_ <= 6; ++at_) {
     if (*at_ == '\t') {
       ++at_;
@@ -282,18 +282,24 @@
         !(*at_ == '0' && column_ == 6)) { // '0' in column 6 becomes space
       EmitChar(token, *at_);
       ++outCol;
-      if (!bad && !IsDecimalDigit(*at_)) {
-        bad = at_;
+      if (!badColumn && (column_ == 6 || !IsDecimalDigit(*at_))) {
+        badColumn = column_;
       }
     }
     ++column_;
   }
-  if (bad && !preprocessor_.IsNameDefined(token.CurrentOpenToken())) {
-    Say(GetProvenance(bad),
-        "Character in fixed-form label field must be a digit"_warn_en_US);
+  if (badColumn && !preprocessor_.IsNameDefined(token.CurrentOpenToken())) {
+    Say(GetProvenance(start + *badColumn - 1),
+        *badColumn == 6
+            ? "Statement should not begin with a continuation line"_warn_en_US
+            : "Character in fixed-form label field must be a digit"_warn_en_US);
     token.clear();
-    at_ = start;
-    return;
+    if (*badColumn < 6) {
+      at_ = start;
+      column_ = 1;
+      return;
+    }
+    outCol = 1;
   }
   if (outCol == 1) { // empty label field
     // Emit a space so that, if the line is rescanned after preprocessing,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142763.492821.patch
Type: text/x-patch
Size: 2414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230127/ef24ff19/attachment-0001.bin>


More information about the flang-commits mailing list