Skip to content

[flang][preprocessor] Handle initial "MACRO&" with no space #98684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,19 @@ void Prescanner::Statement() {
// a comment marker or directive sentinel. If so, disable line
// continuation, so that NextToken() won't consume anything from
// following lines.
if (IsLegalIdentifierStart(*at_) && NextToken(tokens) &&
tokens.SizeInTokens() > 0) {
if (CharBlock id{tokens.TokenAt(0)}; preprocessor_.IsNameDefined(id) &&
if (IsLegalIdentifierStart(*at_)) {
// TODO: Only bother with these cases when any keyword macro has
// been defined with replacement text that could begin a comment
// or directive sentinel.
const char *p{at_};
while (IsLegalInIdentifier(*++p)) {
}
CharBlock id{at_, static_cast<std::size_t>(p - at_)};
if (preprocessor_.IsNameDefined(id) &&
!preprocessor_.IsFunctionLikeDefinition(id)) {
if (auto replaced{preprocessor_.MacroReplacement(tokens, *this)}) {
TokenSequence toks;
toks.Put(id, GetProvenance(at_));
if (auto replaced{preprocessor_.MacroReplacement(toks, *this)}) {
auto newLineClass{ClassifyLine(*replaced, GetCurrentProvenance())};
disableSourceContinuation_ =
newLineClass.kind != LineClassification::Kind::Source;
Expand Down
17 changes: 14 additions & 3 deletions flang/test/Preprocessing/directive-contin-with-pp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

module m
contains
subroutine s(x1, x2, x3, x4, x5, x6, x7)
subroutine s1(x1, x2, x3, x4, x5, x6, x7)

!dir$ ignore_tkr x1

Expand Down Expand Up @@ -51,11 +51,18 @@ subroutine s(x1, x2, x3, x4, x5, x6, x7)
do j3 = 1, n
end do
end
end

COMMENT &
subroutine s2
end subroutine
COMMENT&
subroutine s3
end subroutine
end module

!CHECK: MODULE m
!CHECK: CONTAINS
!CHECK: SUBROUTINE s (x1, x2, x3, x4, x5, x6, x7)
!CHECK: SUBROUTINE s1 (x1, x2, x3, x4, x5, x6, x7)
!CHECK: !DIR$ IGNORE_TKR x1
!CHECK: !DIR$ IGNORE_TKR x2
!CHECK: !DIR$ IGNORE_TKR x3
Expand All @@ -73,4 +80,8 @@ subroutine s(x1, x2, x3, x4, x5, x6, x7)
!CHECK: DO j3=1_4,n
!CHECK: END DO
!CHECK: END SUBROUTINE
!CHECK: SUBROUTINE s2
!CHECK: END SUBROUTINE
!CHECK: SUBROUTINE s3
!CHECK: END SUBROUTINE
!CHECK: END MODULE
Loading