Skip to content

Commit 41a414d

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 41a414d

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,26 +1351,37 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
13511351
}
13521352
p = SkipWhiteSpaceIncludingEmptyMacros(p);
13531353
if (InCompilerDirective()) {
1354-
if (preprocessingOnly_ && directiveSentinel_[0] == '$' &&
1355-
directiveSentinel_[1] == '\0') {
1356-
// in -E mode, don't treat !$ as a continuation
1354+
if (directiveSentinel_[0] == '$' && directiveSentinel_[1] == '\0') {
1355+
if (preprocessingOnly_) {
1356+
// in -E mode, don't treat !$ as a continuation
1357+
return nullptr;
1358+
} else if (p[0] == '!' && p[1] == '$') {
1359+
// accept but do not require a matching sentinel
1360+
if (IsLetter(p[2])) {
1361+
return nullptr; // not !$
1362+
}
1363+
p += 2;
1364+
}
13571365
} else if (*p++ == '!') {
13581366
for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
13591367
if (*s != ToLowerCaseLetter(*p)) {
13601368
return nullptr; // not the same directive class
13611369
}
13621370
}
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;
1371+
} else {
1372+
return nullptr;
1373+
}
1374+
p = SkipWhiteSpace(p);
1375+
if (*p == '&') {
1376+
if (!ampersand) {
1377+
insertASpace_ = true;
13711378
}
1379+
return p + 1;
1380+
} else if (ampersand) {
1381+
return p;
1382+
} else {
1383+
return nullptr;
13721384
}
1373-
return nullptr;
13741385
}
13751386
if (p[0] == '!' && p[1] == '$' && !preprocessingOnly_ &&
13761387
features_.IsEnabled(LanguageFeature::OpenMP)) {

0 commit comments

Comments
 (0)