Skip to content

Commit 1324789

Browse files
authored
[flang][preprocessor] Extend handling of line continuation replacements (#107010)
Codes using traditional C preprocessors will sometimes put a keyword macro name in a free form continuation line in order to get macro replacement of part of an identifier, as in call subr_& &N& &(1.) where N is a keyword macro. f18 already handles this case, but not when there is white space between the macro name and the following continuation marker character '&'. Allow white space to appear. Fixes #106931.
1 parent d1e4a2d commit 1324789

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,16 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
731731
// Subtlety: When an identifier is split across three or more continuation
732732
// lines (or two continuation lines, immediately preceded or followed
733733
// by '&' free form continuation line markers, its parts are kept as
734-
// distinct pp-tokens so that macro operates on them independently.
735-
// This trick accommodates the historic practice of using line
736-
// continuation for token pasting after replacement.
734+
// distinct pp-tokens so that macro replacement operates on them
735+
// independently. This trick accommodates the historic practice of
736+
// using line continuation for token pasting after replacement.
737737
} else if (parts == 2) {
738+
if (afterLast && afterLast < limit_) {
739+
afterLast = SkipWhiteSpace(afterLast);
740+
}
738741
if ((start > start_ && start[-1] == '&') ||
739-
(afterLast < limit_ && (*afterLast == '&' || *afterLast == '\n'))) {
742+
(afterLast && afterLast < limit_ &&
743+
(*afterLast == '&' || *afterLast == '\n'))) {
740744
// call & call foo& call foo&
741745
// &MACRO& OR &MACRO& OR &MACRO
742746
// &foo(...) &(...)

flang/test/Preprocessing/pp134.F90

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
! RUN: %flang -E %s 2>&1 | FileCheck %s
22
! CHECK: print *, ADC, 1
3-
! CHECK: print *, AD, 1
4-
! CHECK: print *, DC, 1
3+
! CHECK: print *, AD, 2
4+
! CHECK: print *, DC, 3
5+
! CHECK: print *, AD(1), 4
56
! CHECK: print *, AD
67
! CHECK: print *, AB
78
#define B D
@@ -12,10 +13,13 @@
1213
&C, 1
1314
print *, A&
1415
&B&
15-
&, 1
16+
&, 2
1617
print *, &
1718
&B&
18-
&C, 1
19+
&C, 3
20+
print *, A&
21+
&B &
22+
&(1), 4
1923
print *, A&
2024
&B
2125
print *, A&

0 commit comments

Comments
 (0)