Skip to content

Cherrypick upstream PR #79628 #31

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

Closed
wants to merge 1 commit into from
Closed
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: 15 additions & 5 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,22 +630,32 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
preventHollerith_ = false;
} else if (IsLegalInIdentifier(*at_)) {
int parts{1};
const char *afterLast{nullptr};
do {
EmitChar(tokens, *at_);
++at_, ++column_;
afterLast = at_;
if (SkipToNextSignificantCharacter() && IsLegalIdentifierStart(*at_)) {
tokens.CloseToken();
++parts;
}
} while (IsLegalInIdentifier(*at_));
if (parts >= 3) {
// Subtlety: When an identifier is split across three or more continuation
// lines, its parts are kept as distinct pp-tokens so that macro
// operates on them independently. This trick accommodates the historic
// practice of using line continuation for token pasting after
// replacement.
// lines (or two continuation lines, immediately preceded or followed
// by '&' free form continuation line markers, its parts are kept as
// distinct pp-tokens so that macro operates on them independently.
// This trick accommodates the historic practice of using line
// continuation for token pasting after replacement.
} else if (parts == 2) {
tokens.ReopenLastToken();
if ((start > start_ && start[-1] == '&') ||
(afterLast < limit_ && (*afterLast == '&' || *afterLast == '\n'))) {
// call & call foo& call foo&
// &MACRO& OR &MACRO& OR &MACRO
// &foo(...) &(...)
} else {
tokens.ReopenLastToken();
}
}
if (InFixedFormSource()) {
SkipSpaces();
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Preprocessing/pp005.F
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK: res = 777
! CHECK: res = (777)
* KWM split across continuation, implicit padding
integer, parameter :: KWM = 666
#define KWM 777
integer :: res
res = KW
+M
res = (KW
+M)
if (res .eq. 777) then
print *, 'pp005.F yes'
else
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Preprocessing/pp006.F
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK: res = 777
! CHECK: res = (777)
* ditto, but with intervening *comment line
integer, parameter :: KWM = 666
#define KWM 777
integer :: res
res = KW
res = (KW
*comment
+M
+M)
if (res .eq. 777) then
print *, 'pp006.F yes'
else
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Preprocessing/pp105.F90
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK: res = 777
! CHECK: res = (777)
! KWM call name split across continuation, with leading &
integer, parameter :: KWM = 666
#define KWM 777
integer :: res
res = KW&
&M
res = (KW&
&M)
if (res .eq. 777) then
print *, 'pp105.F90 yes'
else
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Preprocessing/pp106.F90
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK: res = 777
! CHECK: res = (777)
! ditto, with & ! comment
integer, parameter :: KWM = 666
#define KWM 777
integer :: res
res = KW& ! comment
&M
res = (KW& ! comment
&M)
if (res .eq. 777) then
print *, 'pp106.F90 yes'
else
Expand Down
18 changes: 16 additions & 2 deletions flang/test/Preprocessing/pp134.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK: print *, ADC
! CHECK: print *, ADC, 1
! CHECK: print *, AD, 1
! CHECK: print *, DC, 1
! CHECK: print *, AD
! CHECK: print *, AB
#define B D
implicit none
real ADC
print *, A&
&B&
&C
&C, 1
print *, A&
&B&
&, 1
print *, &
&B&
&C, 1
print *, A&
&B
print *, A&
&B ! but not this
end