[flang-commits] [flang] 8a1f12c - [flang] Warn about more continuation lines than the standard permits

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Dec 2 17:07:19 PST 2022


Author: Peter Klausler
Date: 2022-12-02T17:07:11-08:00
New Revision: 8a1f12c6fbe9da8dcb6102d3b9b695cfcae9dbb4

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

LOG: [flang] Warn about more continuation lines than the standard permits

f18 doesn't have any limit on continuation lines in fixed or free form
source (other than available memory), but the standard does.  Emit
a portability warning when it is exceeded.

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

Added: 
    flang/test/Parser/excessive-continuations.f90

Modified: 
    flang/docs/Extensions.md
    flang/lib/Parser/prescan.cpp
    flang/lib/Parser/prescan.h

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index ed0229d9c2eba..039b1f9e7f078 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -240,6 +240,8 @@ end
 * The legacy extension intrinsic functions `IZEXT` and `JZEXT`
   are supported; `ZEXT` has 
diff erent behavior with various older
   compilers, so it is not supported.
+* f18 doesn't impose a limit on the number of continuation lines
+  allowed for a single statement.
 
 ### Extensions supported when enabled by options
 

diff  --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 17fc090c8c9c0..ae8decfdf8369 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -89,7 +89,8 @@ void Prescanner::Prescan(ProvenanceRange range) {
 
 void Prescanner::Statement() {
   TokenSequence tokens;
-  LineClassification line{ClassifyLine(nextLine_)};
+  const char *statementStart{nextLine_};
+  LineClassification line{ClassifyLine(statementStart)};
   switch (line.kind) {
   case LineClassification::Kind::Comment:
     nextLine_ += line.payloadOffset; // advance to '!' or newline
@@ -164,6 +165,11 @@ void Prescanner::Statement() {
 
   while (NextToken(tokens)) {
   }
+  if (continuationLines_ > 255) {
+    Say(GetProvenance(statementStart),
+        "%d continuation lines is more than the Fortran standard allows"_port_en_US,
+        continuationLines_);
+  }
 
   Provenance newlineProvenance{GetCurrentProvenance()};
   if (std::optional<TokenSequence> preprocessed{
@@ -299,7 +305,7 @@ void Prescanner::LabelField(TokenSequence &token) {
   token.CloseToken();
   SkipToNextSignificantCharacter();
   if (IsDecimalDigit(*at_)) {
-    Say(GetProvenance(at_),
+    Say(GetCurrentProvenance(),
         "Label digit is not in fixed-form label field"_port_en_US);
   }
 }
@@ -406,6 +412,7 @@ void Prescanner::SkipToNextSignificantCharacter() {
       mightNeedSpace = *at_ == '\n';
     }
     for (; Continuation(mightNeedSpace); mightNeedSpace = false) {
+      ++continuationLines_;
       if (MustSkipToEndOfLine()) {
         SkipToEndOfLine();
       }
@@ -493,7 +500,7 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
       // Recognize and skip over classic C style /*comments*/ when
       // outside a character literal.
       if (features_.ShouldWarn(LanguageFeature::ClassicCComments)) {
-        Say(GetProvenance(at_),
+        Say(GetCurrentProvenance(),
             "nonstandard usage: C-style comment"_port_en_US);
       }
       SkipCComments();

diff  --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h
index 4d002add8496d..ad8b90b0560e5 100644
--- a/flang/lib/Parser/prescan.h
+++ b/flang/lib/Parser/prescan.h
@@ -109,6 +109,7 @@ class Prescanner {
     slashInCurrentStatement_ = false;
     preventHollerith_ = false;
     delimiterNesting_ = 0;
+    continuationLines_ = 0;
   }
 
   Provenance GetProvenance(const char *sourceChar) const {
@@ -195,6 +196,7 @@ class Prescanner {
   Encoding encoding_{Encoding::UTF_8};
   int delimiterNesting_{0};
   int prescannerNesting_{0};
+  int continuationLines_{0};
 
   Provenance startProvenance_;
   const char *start_{nullptr}; // beginning of current source file content

diff  --git a/flang/test/Parser/excessive-continuations.f90 b/flang/test/Parser/excessive-continuations.f90
new file mode 100644
index 0000000000000..e5855cfcbe526
--- /dev/null
+++ b/flang/test/Parser/excessive-continuations.f90
@@ -0,0 +1,262 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+! CHECK: portability: 256 continuation lines is more than the Fortran standard allows
+! CHECK: LOGICAL, PARAMETER :: c255 = .true._4
+program test
+  logical, parameter :: c255 = 255 == len("&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+ &a&
+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