Skip to content

Commit 2849e11

Browse files
committed
[flang] Handle @process directive
Treat lines that start with @process as a comment line. The directive is accepted and ignored. Differential Revision: https://reviews.llvm.org/D150883
1 parent 33d3d51 commit 2849e11

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

flang/docs/Extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ end
363363
* Constraint C1406, which prohibits the same module name from being used
364364
in a scope for both an intrinsic and a non-intrinsic module, is implemented
365365
as a portability warning only, not a hard error.
366+
* IBM @PROCESS directive is accepted but ignored.
366367

367368
## Preprocessing behavior
368369

flang/lib/Parser/prescan.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,23 @@ bool Prescanner::PadOutCharacterLiteral(TokenSequence &tokens) {
777777
return false;
778778
}
779779

780+
static bool IsAtProcess(const char *p) {
781+
static const char pAtProc[]{"process"};
782+
for (std::size_t i{0}; i < sizeof pAtProc - 1; ++i) {
783+
if (ToLowerCaseLetter(*++p) != pAtProc[i])
784+
return false;
785+
}
786+
return true;
787+
}
788+
780789
bool Prescanner::IsFixedFormCommentLine(const char *start) const {
781790
const char *p{start};
791+
792+
// The @process directive must start in column 1.
793+
if (*p == '@' && IsAtProcess(p)) {
794+
return true;
795+
}
796+
782797
if (IsFixedFormCommentChar(*p) || *p == '%' || // VAX %list, %eject, &c.
783798
((*p == 'D' || *p == 'd') &&
784799
!features_.IsEnabled(LanguageFeature::OldDebugLines))) {
@@ -810,6 +825,8 @@ const char *Prescanner::IsFreeFormComment(const char *p) const {
810825
p = SkipWhiteSpaceAndCComments(p);
811826
if (*p == '!' || *p == '\n') {
812827
return p;
828+
} else if (*p == '@') {
829+
return IsAtProcess(p) ? p : nullptr;
813830
} else {
814831
return nullptr;
815832
}

flang/test/Parser/at-process.f

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
2+
3+
! Test ignoring @PROCESS directive in fixed source form
4+
5+
@process opt(3)
6+
@process opt(0)
7+
@process
8+
@processopt(3)
9+
subroutine f()
10+
c@process
11+
end
12+
13+
!CHECK: Character in fixed-form label field must be a digit
14+
@
15+
16+
!CHECK: Character in fixed-form label field must be a digit
17+
@proce
18+
19+
!CHECK: Character in fixed-form label field must be a digit
20+
@precoss

flang/test/Parser/at-process.f90

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
2+
3+
! Test ignoring @PROCESS directive in free source form
4+
5+
@process opt(3)
6+
@process opt(0)
7+
@process strict
8+
@processopt(3)
9+
subroutine f()
10+
print *, "@process"
11+
! @process
12+
end subroutine f
13+
14+
!CHECK: error: expected '('
15+
@p
16+
17+
!CHECK: error: expected '('
18+
@proce
19+
20+
!CHECK: error: expected '('
21+
@precoss
22+
end
23+

0 commit comments

Comments
 (0)