[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
Sat Jan 28 10:51:44 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG82d7a6b2bbc9: [flang] Diagnose fixed form statement that begins with continuation line (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

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.493022.patch
Type: text/x-patch
Size: 2414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230128/1b6b0743/attachment.bin>


More information about the flang-commits mailing list