Skip to content

Commit 0d097cb

Browse files
committed
[flang][OpenMP] Fix regression in !$ continuation
A recent patch that obviated the need to use -fopenmp when using the compiler to preprocess in -E mode broke a case of Fortran line continuation when using OpenMP conditional compilation lines (!$) when *not* in -E mode. Fix.
1 parent 5942f02 commit 0d097cb

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,17 +1278,23 @@ const char *Prescanner::FixedFormContinuationLine(bool mightNeedSpace) {
12781278
tabInCurrentLine_ = false;
12791279
char col1{*nextLine_};
12801280
if (InCompilerDirective()) {
1281-
if (preprocessingOnly_ && directiveSentinel_[0] == '$' &&
1282-
directiveSentinel_[1] == '\0') {
1283-
// in -E mode, don't treat "!$ &" as a continuation
1281+
if (directiveSentinel_[0] == '$' && directiveSentinel_[1] == '\0') {
1282+
if (preprocessingOnly_) {
1283+
// in -E mode, don't treat "!$ &" as a continuation
1284+
return nullptr;
1285+
} else if (IsFixedFormCommentChar(col1) && nextLine_[1] == '$') {
1286+
// accept but do not require a matching sentinel
1287+
if (IsLetter(nextLine_[2])) {
1288+
return nullptr; // not !$
1289+
}
1290+
}
12841291
} else if (IsFixedFormCommentChar(col1)) {
12851292
int j{1};
12861293
for (; j < 5; ++j) {
12871294
char ch{directiveSentinel_[j - 1]};
12881295
if (ch == '\0') {
12891296
break;
1290-
}
1291-
if (ch != ToLowerCaseLetter(nextLine_[j])) {
1297+
} else if (ch != ToLowerCaseLetter(nextLine_[j])) {
12921298
return nullptr;
12931299
}
12941300
}
@@ -1297,13 +1303,15 @@ const char *Prescanner::FixedFormContinuationLine(bool mightNeedSpace) {
12971303
return nullptr;
12981304
}
12991305
}
1300-
const char *col6{nextLine_ + 5};
1301-
if (*col6 != '\n' && *col6 != '0' && !IsSpaceOrTab(col6)) {
1302-
if (mightNeedSpace && !IsSpace(nextLine_ + 6)) {
1303-
insertASpace_ = true;
1304-
}
1305-
return nextLine_ + 6;
1306+
} else {
1307+
return nullptr;
1308+
}
1309+
const char *col6{nextLine_ + 5};
1310+
if (*col6 != '\n' && *col6 != '0' && !IsSpaceOrTab(col6)) {
1311+
if (mightNeedSpace && !IsSpace(nextLine_ + 6)) {
1312+
insertASpace_ = true;
13061313
}
1314+
return nextLine_ + 6;
13071315
}
13081316
} else {
13091317
// Normal case: not in a compiler directive.
@@ -1351,26 +1359,37 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
13511359
}
13521360
p = SkipWhiteSpaceIncludingEmptyMacros(p);
13531361
if (InCompilerDirective()) {
1354-
if (preprocessingOnly_ && directiveSentinel_[0] == '$' &&
1355-
directiveSentinel_[1] == '\0') {
1356-
// in -E mode, don't treat !$ as a continuation
1362+
if (directiveSentinel_[0] == '$' && directiveSentinel_[1] == '\0') {
1363+
if (preprocessingOnly_) {
1364+
// in -E mode, don't treat !$ as a continuation
1365+
return nullptr;
1366+
} else if (p[0] == '!' && p[1] == '$') {
1367+
// accept but do not require a matching sentinel
1368+
if (IsLetter(p[2])) {
1369+
return nullptr; // not !$
1370+
}
1371+
p += 2;
1372+
}
13571373
} else if (*p++ == '!') {
13581374
for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
13591375
if (*s != ToLowerCaseLetter(*p)) {
13601376
return nullptr; // not the same directive class
13611377
}
13621378
}
1363-
p = SkipWhiteSpace(p);
1364-
if (*p == '&') {
1365-
if (!ampersand) {
1366-
insertASpace_ = true;
1367-
}
1368-
return p + 1;
1369-
} else if (ampersand) {
1370-
return p;
1379+
} else {
1380+
return nullptr;
1381+
}
1382+
p = SkipWhiteSpace(p);
1383+
if (*p == '&') {
1384+
if (!ampersand) {
1385+
insertASpace_ = true;
13711386
}
1387+
return p + 1;
1388+
} else if (ampersand) {
1389+
return p;
1390+
} else {
1391+
return nullptr;
13721392
}
1373-
return nullptr;
13741393
}
13751394
if (p[0] == '!' && p[1] == '$' && !preprocessingOnly_ &&
13761395
features_.IsEnabled(LanguageFeature::OpenMP)) {

0 commit comments

Comments
 (0)