Skip to content

[flang] Handle continuation line edge case #74751

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
Dec 11, 2023
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
20 changes: 11 additions & 9 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ void Prescanner::QuotedCharacterLiteral(
char quote{*at_};
const char *end{at_ + 1};
inCharLiteral_ = true;
continuationInCharLiteral_ = true;
const auto emit{[&](char ch) { EmitChar(tokens, ch); }};
const auto insert{[&](char ch) { EmitInsertedChar(tokens, ch); }};
bool isEscaped{false};
Expand Down Expand Up @@ -749,16 +750,9 @@ void Prescanner::QuotedCharacterLiteral(
break;
}
inCharLiteral_ = true;
if (insertASpace_) {
if (features_.ShouldWarn(
common::LanguageFeature::MiscSourceExtensions)) {
Say(GetProvenanceRange(at_, end),
"Repeated quote mark in character literal continuation line should have been preceded by '&'"_port_en_US);
}
insertASpace_ = false;
}
}
}
continuationInCharLiteral_ = false;
inCharLiteral_ = false;
}

Expand Down Expand Up @@ -1122,7 +1116,15 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
} else if (*p == '!' || *p == '\n' || *p == '#') {
return nullptr;
} else if (ampersand || IsImplicitContinuation()) {
if (p > nextLine_) {
if (continuationInCharLiteral_) {
// 'a'& -> 'a''b' == "a'b"
// 'b'
if (features_.ShouldWarn(
common::LanguageFeature::MiscSourceExtensions)) {
Say(GetProvenanceRange(p, p + 1),
"Character literal continuation line should have been preceded by '&'"_port_en_US);
}
} else if (p > nextLine_) {
--p;
} else {
insertASpace_ = true;
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Parser/prescan.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class Prescanner {
bool slashInCurrentStatement_{false};
bool preventHollerith_{false}; // CHARACTER*4HIMOM not Hollerith
bool inCharLiteral_{false};
bool continuationInCharLiteral_{false};
bool inPreprocessorDirective_{false};

// In some edge cases of compiler directive continuation lines, it
Expand Down
10 changes: 0 additions & 10 deletions flang/test/Parser/continuation-before-quote.f90

This file was deleted.

13 changes: 13 additions & 0 deletions flang/test/Parser/continuation-without-ampersand.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
! Continuation between repeated quotation marks
subroutine test
!CHECK: portability: Character literal continuation line should have been preceded by '&'
print *, 'needs an '&
'ampersand'''
!CHECK: portability: Character literal continuation line should have been preceded by '&'
print *, 'also needs an '&
'ampersand'''
!CHECK-NOT: portability: Character literal continuation line should have been preceded by '&'
print *, 'has an '&
&'ampersand'''
end