Skip to content

Commit 26330a0

Browse files
committed
[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
1 parent e8425b2 commit 26330a0

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ void Prescanner::NextLine() {
246246
}
247247

248248
void Prescanner::LabelField(TokenSequence &token, int outCol) {
249+
bool badLabel{false};
249250
for (; *at_ != '\n' && column_ <= 6; ++at_) {
250251
if (*at_ == '\t') {
251252
++at_;
@@ -255,24 +256,23 @@ void Prescanner::LabelField(TokenSequence &token, int outCol) {
255256
if (*at_ != ' ' &&
256257
!(*at_ == '0' && column_ == 6)) { // '0' in column 6 becomes space
257258
EmitChar(token, *at_);
259+
if (!IsDecimalDigit(*at_) && !badLabel) {
260+
Say(GetProvenance(at_),
261+
"Character in fixed-form label field must be a digit"_en_US);
262+
badLabel = true;
263+
}
258264
++outCol;
259265
}
260266
++column_;
261267
}
262268
if (outCol > 1) {
263269
token.CloseToken();
264270
}
265-
if (outCol < 7) {
266-
if (outCol == 1) {
267-
token.Put(" ", 6, sixSpaceProvenance_.start());
268-
} else {
269-
for (; outCol < 7; ++outCol) {
270-
token.PutNextTokenChar(' ', spaceProvenance_);
271-
}
272-
token.CloseToken();
273-
}
274-
}
275271
SkipToNextSignificantCharacter();
272+
if (IsDecimalDigit(*at_)) {
273+
Say(GetProvenance(at_),
274+
"Label digit is not in fixed-form label field"_en_US);
275+
}
276276
}
277277

278278
void Prescanner::SkipToEndOfLine() {

flang/lib/Parser/prescan.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ class Prescanner {
220220
cooked_.allSources().CompilerInsertionProvenance(' ')};
221221
const Provenance backslashProvenance_{
222222
cooked_.allSources().CompilerInsertionProvenance('\\')};
223-
const ProvenanceRange sixSpaceProvenance_{
224-
cooked_.allSources().AddCompilerInsertion(" "s)};
225223

226224
// To avoid probing the set of active compiler directive sentinel strings
227225
// on every comment line, they're checked first with a cheap Bloom filter.

flang/test/Parser/badlabel.f

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! RUN: %f18 -E %s 2>&1 | FileCheck %s
2+
! CHECK: Label digit is not in fixed-form label field
3+
1 continue
4+
! CHECK: Label digit is not in fixed-form label field
5+
1 2 continue
6+
! CHECK-NOT: Label is not in fixed-form label field
7+
con
8+
3 tinue
9+
! CHECK: Character in fixed-form label field must be a digit
10+
end
11+
! CHECK: 1continue
12+
! CHECK: 12continue
13+
! CHECK: continue
14+
! CHECK: end

0 commit comments

Comments
 (0)