Skip to content

Commit

Permalink
[flang] Handle @process directive
Browse files Browse the repository at this point in the history
Treat lines that start with @process as a comment line. The directive
is accepted and ignored.

Differential Revision: https://reviews.llvm.org/D150883
  • Loading branch information
kkwli committed May 22, 2023
1 parent 33d3d51 commit 2849e11
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions flang/docs/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ end
* Constraint C1406, which prohibits the same module name from being used
in a scope for both an intrinsic and a non-intrinsic module, is implemented
as a portability warning only, not a hard error.
* IBM @PROCESS directive is accepted but ignored.

## Preprocessing behavior

Expand Down
17 changes: 17 additions & 0 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,23 @@ bool Prescanner::PadOutCharacterLiteral(TokenSequence &tokens) {
return false;
}

static bool IsAtProcess(const char *p) {
static const char pAtProc[]{"process"};
for (std::size_t i{0}; i < sizeof pAtProc - 1; ++i) {
if (ToLowerCaseLetter(*++p) != pAtProc[i])
return false;
}
return true;
}

bool Prescanner::IsFixedFormCommentLine(const char *start) const {
const char *p{start};

// The @process directive must start in column 1.
if (*p == '@' && IsAtProcess(p)) {
return true;
}

if (IsFixedFormCommentChar(*p) || *p == '%' || // VAX %list, %eject, &c.
((*p == 'D' || *p == 'd') &&
!features_.IsEnabled(LanguageFeature::OldDebugLines))) {
Expand Down Expand Up @@ -810,6 +825,8 @@ const char *Prescanner::IsFreeFormComment(const char *p) const {
p = SkipWhiteSpaceAndCComments(p);
if (*p == '!' || *p == '\n') {
return p;
} else if (*p == '@') {
return IsAtProcess(p) ? p : nullptr;
} else {
return nullptr;
}
Expand Down
20 changes: 20 additions & 0 deletions flang/test/Parser/at-process.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s

! Test ignoring @PROCESS directive in fixed source form

@process opt(3)
@process opt(0)
@process
@processopt(3)
subroutine f()
c@process
end

!CHECK: Character in fixed-form label field must be a digit
@

!CHECK: Character in fixed-form label field must be a digit
@proce

!CHECK: Character in fixed-form label field must be a digit
@precoss
23 changes: 23 additions & 0 deletions flang/test/Parser/at-process.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s

! Test ignoring @PROCESS directive in free source form

@process opt(3)
@process opt(0)
@process strict
@processopt(3)
subroutine f()
print *, "@process"
! @process
end subroutine f

!CHECK: error: expected '('
@p

!CHECK: error: expected '('
@proce

!CHECK: error: expected '('
@precoss
end

0 comments on commit 2849e11

Please sign in to comment.