[flang-commits] [flang] 26330a0 - [flang] Check for misplaced labels

peter klausler via flang-commits flang-commits at lists.llvm.org
Tue Jul 21 18:01:00 PDT 2020


Author: peter klausler
Date: 2020-07-21T18:00:16-07:00
New Revision: 26330a0c7c6e26881a139ed84b75d86b9903dd73

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

LOG: [flang] Check for misplaced labels

In fixed form source, complain when a label digit appears
outside the label field & when a non-digit appears in the label
field.

Reviewed By: sscalpone

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

Added: 
    flang/test/Parser/badlabel.f

Modified: 
    flang/lib/Parser/prescan.cpp
    flang/lib/Parser/prescan.h

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 07ddbddaa08d..68e1de1e5e44 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -246,6 +246,7 @@ void Prescanner::NextLine() {
 }
 
 void Prescanner::LabelField(TokenSequence &token, int outCol) {
+  bool badLabel{false};
   for (; *at_ != '\n' && column_ <= 6; ++at_) {
     if (*at_ == '\t') {
       ++at_;
@@ -255,6 +256,11 @@ void Prescanner::LabelField(TokenSequence &token, int outCol) {
     if (*at_ != ' ' &&
         !(*at_ == '0' && column_ == 6)) { // '0' in column 6 becomes space
       EmitChar(token, *at_);
+      if (!IsDecimalDigit(*at_) && !badLabel) {
+        Say(GetProvenance(at_),
+            "Character in fixed-form label field must be a digit"_en_US);
+        badLabel = true;
+      }
       ++outCol;
     }
     ++column_;
@@ -262,17 +268,11 @@ void Prescanner::LabelField(TokenSequence &token, int outCol) {
   if (outCol > 1) {
     token.CloseToken();
   }
-  if (outCol < 7) {
-    if (outCol == 1) {
-      token.Put("      ", 6, sixSpaceProvenance_.start());
-    } else {
-      for (; outCol < 7; ++outCol) {
-        token.PutNextTokenChar(' ', spaceProvenance_);
-      }
-      token.CloseToken();
-    }
-  }
   SkipToNextSignificantCharacter();
+  if (IsDecimalDigit(*at_)) {
+    Say(GetProvenance(at_),
+        "Label digit is not in fixed-form label field"_en_US);
+  }
 }
 
 void Prescanner::SkipToEndOfLine() {

diff  --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h
index 3a08a90c3679..393016fde369 100644
--- a/flang/lib/Parser/prescan.h
+++ b/flang/lib/Parser/prescan.h
@@ -220,8 +220,6 @@ class Prescanner {
       cooked_.allSources().CompilerInsertionProvenance(' ')};
   const Provenance backslashProvenance_{
       cooked_.allSources().CompilerInsertionProvenance('\\')};
-  const ProvenanceRange sixSpaceProvenance_{
-      cooked_.allSources().AddCompilerInsertion("      "s)};
 
   // To avoid probing the set of active compiler directive sentinel strings
   // on every comment line, they're checked first with a cheap Bloom filter.

diff  --git a/flang/test/Parser/badlabel.f b/flang/test/Parser/badlabel.f
new file mode 100644
index 000000000000..28008bd809d9
--- /dev/null
+++ b/flang/test/Parser/badlabel.f
@@ -0,0 +1,14 @@
+! RUN: %f18 -E %s 2>&1 | FileCheck %s
+! CHECK: Label digit is not in fixed-form label field
+      1 continue
+! CHECK: Label digit is not in fixed-form label field
+ 1    2 continue
+! CHECK-NOT: Label is not in fixed-form label field
+      con
+     3 tinue
+! CHECK: Character in fixed-form label field must be a digit
+end
+! CHECK: 1continue
+! CHECK: 12continue
+! CHECK: continue
+! CHECK: end


        


More information about the flang-commits mailing list