Skip to content

[flang][OpenMP] Skip invalid conditional compilation sentinels #126282

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
Feb 13, 2025
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
15 changes: 15 additions & 0 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,21 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
}
*sp++ = ToLowerCaseLetter(*p);
}
// A fixed form OpenMP conditional compilation sentinel must satisfy the
// following criteria, for initial lines:
// - Columns 3 through 5 must have only white space or numbers.
// - Column 6 must be space or zero.
if (column == 3 && sentinel[0] == '$') {
const char *q{p};
for (int col{3}; col < 6; ++col, ++q) {
if (!IsSpaceOrTab(q) && !IsDecimalDigit(*q)) {
return std::nullopt;
}
}
if (*q != ' ' && *q != '0') {
return std::nullopt;
}
}
if (column == 6) {
if (*p == '0') {
++p;
Expand Down
30 changes: 30 additions & 0 deletions flang/test/Parser/OpenMP/sentinels.f
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,34 @@ subroutine sub(a, b)
C $ This is a comment line
c $ his is a comment line
* $ This is a comment line

! Test non-space/non-number char in columns 3-5, for initial lines.
! CHECK-NOT: "comment"
c$x PRINT *, "comment"
c$ + PRINT *, "comment"
c$ * PRINT *, "comment"

! Test non-space/non-number char in columns 3-5, for continuation lines.
! CHECK: "msg1"
! CHECK-NOT: "comment"
c$ x PRINT *, "comment"
c$1 & , "comment"
c$ x & , "comment"
c$ +& , "comment"

c$ PRINT *, "msg1"
c$1 & , "comment"
c$ x & , "comment"
c$ +& , "comment"

! Test valid chars in initial and continuation lines.
! CHECK: "msg2"
! CHECK-SAME: "msg3"
c$ 20 PRINT *, "msg2"
c$ & , "msg3"

! CHECK: "msg4"
! CHECK-SAME: "msg5"
c$ 0PRINT *, "msg4",
c$ + "msg5"
end