[flang-commits] [flang] 2849e11 - [flang] Handle @PROCESS directive
Kelvin Li via flang-commits
flang-commits at lists.llvm.org
Sun May 21 19:41:15 PDT 2023
Author: Kelvin Li
Date: 2023-05-21T22:37:28-04:00
New Revision: 2849e11907c6dfea40ab41773654f202817934e5
URL: https://github.com/llvm/llvm-project/commit/2849e11907c6dfea40ab41773654f202817934e5
DIFF: https://github.com/llvm/llvm-project/commit/2849e11907c6dfea40ab41773654f202817934e5.diff
LOG: [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
Added:
flang/test/Parser/at-process.f
flang/test/Parser/at-process.f90
Modified:
flang/docs/Extensions.md
flang/lib/Parser/prescan.cpp
Removed:
################################################################################
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index a91596765a594..a422b2c7eb0a4 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -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
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 27b5597db4259..2bbf1d67eb626 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -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))) {
@@ -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;
}
diff --git a/flang/test/Parser/at-process.f b/flang/test/Parser/at-process.f
new file mode 100644
index 0000000000000..41b95044bfdc5
--- /dev/null
+++ b/flang/test/Parser/at-process.f
@@ -0,0 +1,20 @@
+! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
+
+! Test ignoring @PROCESS directive in fixed source form
+
+ at process opt(3)
+ at process opt(0)
+ at process
+ at processopt(3)
+ subroutine f()
+c at process
+ end
+
+!CHECK: Character in fixed-form label field must be a digit
+@
+
+!CHECK: Character in fixed-form label field must be a digit
+ at proce
+
+!CHECK: Character in fixed-form label field must be a digit
+ at precoss
diff --git a/flang/test/Parser/at-process.f90 b/flang/test/Parser/at-process.f90
new file mode 100644
index 0000000000000..cd5b2acf3f3e0
--- /dev/null
+++ b/flang/test/Parser/at-process.f90
@@ -0,0 +1,23 @@
+! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
+
+! Test ignoring @PROCESS directive in free source form
+
+ at process opt(3)
+ at process opt(0)
+ @process strict
+ at processopt(3)
+subroutine f()
+print *, "@process"
+ ! @process
+end subroutine f
+
+!CHECK: error: expected '('
+ at p
+
+!CHECK: error: expected '('
+ at proce
+
+!CHECK: error: expected '('
+ at precoss
+end
+
More information about the flang-commits
mailing list