diff --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h --- a/flang/lib/Parser/prescan.h +++ b/flang/lib/Parser/prescan.h @@ -220,8 +220,6 @@ 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/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp --- a/flang/lib/Parser/prescan.cpp +++ b/flang/lib/Parser/prescan.cpp @@ -246,6 +246,7 @@ } void Prescanner::LabelField(TokenSequence &token, int outCol) { + bool badLabel{false}; for (; *at_ != '\n' && column_ <= 6; ++at_) { if (*at_ == '\t') { ++at_; @@ -255,6 +256,11 @@ 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 @@ 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/test/Parser/badlabel.f b/flang/test/Parser/badlabel.f new file mode 100644 --- /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