Skip to content

Commit bde2f39

Browse files
authored
[flang] Don't check fixed form label field too early (#117040)
When a fixed form source line begins with the name of a macro, don't emit the usual warning message about a non-decimal character in the label field. (The check for a macro was only being applied to free form source lines, and the label field checking was unconditional). Fixes #116914.
1 parent be6bc6a commit bde2f39

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,15 @@ void Prescanner::Statement() {
188188
}
189189
break;
190190
}
191-
case LineClassification::Kind::Source:
191+
case LineClassification::Kind::Source: {
192192
BeginStatementAndAdvance();
193+
bool checkLabelField{false};
193194
if (inFixedForm_) {
194195
if (features_.IsEnabled(LanguageFeature::OldDebugLines) &&
195196
(*at_ == 'D' || *at_ == 'd')) {
196197
NextChar();
197198
}
198-
LabelField(tokens);
199+
checkLabelField = true;
199200
} else {
200201
if (skipLeadingAmpersand_) {
201202
skipLeadingAmpersand_ = false;
@@ -207,38 +208,42 @@ void Prescanner::Statement() {
207208
} else {
208209
SkipSpaces();
209210
}
210-
// Check for a leading identifier that might be a keyword macro
211-
// that will expand to anything indicating a non-source line, like
212-
// a comment marker or directive sentinel. If so, disable line
213-
// continuation, so that NextToken() won't consume anything from
214-
// following lines.
215-
if (IsLegalIdentifierStart(*at_)) {
216-
// TODO: Only bother with these cases when any keyword macro has
217-
// been defined with replacement text that could begin a comment
218-
// or directive sentinel.
219-
const char *p{at_};
220-
while (IsLegalInIdentifier(*++p)) {
221-
}
222-
CharBlock id{at_, static_cast<std::size_t>(p - at_)};
223-
if (preprocessor_.IsNameDefined(id) &&
224-
!preprocessor_.IsFunctionLikeDefinition(id)) {
225-
TokenSequence toks;
226-
toks.Put(id, GetProvenance(at_));
227-
if (auto replaced{preprocessor_.MacroReplacement(toks, *this)}) {
228-
auto newLineClass{ClassifyLine(*replaced, GetCurrentProvenance())};
229-
if (newLineClass.kind ==
230-
LineClassification::Kind::CompilerDirective) {
231-
directiveSentinel_ = newLineClass.sentinel;
232-
disableSourceContinuation_ = false;
233-
} else {
234-
disableSourceContinuation_ =
235-
newLineClass.kind != LineClassification::Kind::Source;
236-
}
211+
}
212+
// Check for a leading identifier that might be a keyword macro
213+
// that will expand to anything indicating a non-source line, like
214+
// a comment marker or directive sentinel. If so, disable line
215+
// continuation, so that NextToken() won't consume anything from
216+
// following lines.
217+
if (IsLegalIdentifierStart(*at_)) {
218+
// TODO: Only bother with these cases when any keyword macro has
219+
// been defined with replacement text that could begin a comment
220+
// or directive sentinel.
221+
const char *p{at_};
222+
while (IsLegalInIdentifier(*++p)) {
223+
}
224+
CharBlock id{at_, static_cast<std::size_t>(p - at_)};
225+
if (preprocessor_.IsNameDefined(id) &&
226+
!preprocessor_.IsFunctionLikeDefinition(id)) {
227+
checkLabelField = false;
228+
TokenSequence toks;
229+
toks.Put(id, GetProvenance(at_));
230+
if (auto replaced{preprocessor_.MacroReplacement(toks, *this)}) {
231+
auto newLineClass{ClassifyLine(*replaced, GetCurrentProvenance())};
232+
if (newLineClass.kind ==
233+
LineClassification::Kind::CompilerDirective) {
234+
directiveSentinel_ = newLineClass.sentinel;
235+
disableSourceContinuation_ = false;
236+
} else {
237+
disableSourceContinuation_ =
238+
newLineClass.kind != LineClassification::Kind::Source;
237239
}
238240
}
239241
}
240242
}
241-
break;
243+
if (checkLabelField) {
244+
LabelField(tokens);
245+
}
246+
} break;
242247
}
243248

244249
while (NextToken(tokens)) {

flang/test/Preprocessing/pp046.F

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! RUN: %flang -E %s 2>&1 | FileCheck %s
2+
! CHECK-NOT: Character in fixed-form label field must be a digit
3+
#define KWM !
4+
KWM a comment
5+
end

0 commit comments

Comments
 (0)