[flang-commits] [flang] [Flang][OpenMP] Fix compilation error when a line with Fixed Source Form Conditional Compilation Sentinels is a continuation line (PR #70309)
via flang-commits
flang-commits at lists.llvm.org
Mon Oct 30 20:27:49 PDT 2023
https://github.com/sihuan updated https://github.com/llvm/llvm-project/pull/70309
>From 766c4807b77c267f29be73c1e730cde8f0cca375 Mon Sep 17 00:00:00 2001
From: SiHuaN <liyongtai at iscas.ac.cn>
Date: Thu, 26 Oct 2023 16:45:22 +0800
Subject: [PATCH 1/3] [Flang][OpenMP] Fix compilation error when a line with
Fixed Source Form Conditional Compilation Sentinels is a continuation line
---
flang/lib/Parser/prescan.cpp | 29 ++++++++++++-------
.../continuation-in-conditional-compilation.f | 16 ++++++++++
2 files changed, 34 insertions(+), 11 deletions(-)
create mode 100644 flang/test/Parser/continuation-in-conditional-compilation.f
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 2f25b02bf7a323d..de0d66a6bd50df2 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -997,20 +997,27 @@ const char *Prescanner::FixedFormContinuationLine(bool mightNeedSpace) {
}
tabInCurrentLine_ = false;
char col1{*nextLine_};
- if (InCompilerDirective()) {
- // Must be a continued compiler directive.
- if (!IsFixedFormCommentChar(col1)) {
- return nullptr;
- }
+ if (InCompilerDirective() ||
+ (features_.IsEnabled(LanguageFeature::OpenMP) &&
+ IsFixedFormCommentChar(col1) && nextLine_[1] == '$')) {
int j{1};
- for (; j < 5; ++j) {
- char ch{directiveSentinel_[j - 1]};
- if (ch == '\0') {
- break;
- }
- if (ch != ToLowerCaseLetter(nextLine_[j])) {
+ if (InCompilerDirective()) {
+ // Must be a continued compiler directive.
+ if (!IsFixedFormCommentChar(col1)) {
return nullptr;
}
+ for (; j < 5; ++j) {
+ char ch{directiveSentinel_[j - 1]};
+ if (ch == '\0') {
+ break;
+ }
+ if (ch != ToLowerCaseLetter(nextLine_[j])) {
+ return nullptr;
+ }
+ }
+ } else {
+ // Fixed Source Form Conditional Compilation Sentinels.
+ j = 2;
}
for (; j < 5; ++j) {
if (nextLine_[j] != ' ') {
diff --git a/flang/test/Parser/continuation-in-conditional-compilation.f b/flang/test/Parser/continuation-in-conditional-compilation.f
new file mode 100644
index 000000000000000..92b74f089475b74
--- /dev/null
+++ b/flang/test/Parser/continuation-in-conditional-compilation.f
@@ -0,0 +1,16 @@
+! RUN: %flang_fc1 -fopenmp -fopenacc -E %s 2>&1 | FileCheck %s
+ program main
+! CHECK: k01=1+1
+ k01=1+
+!$ & 1
+
+! CHECK: !$omp parallel
+!$omp para
+!$omp+llel
+!$omp end parallel
+
+! CHECK-NOT: comment
+!$omp parallel
+!$acc+comment
+!$omp end parallel
+ end
>From 54a483117cb5649e4782f1e2a736f2faa03275ca Mon Sep 17 00:00:00 2001
From: SiHuaN <sihuan at sakuya.love>
Date: Fri, 27 Oct 2023 22:24:49 +0800
Subject: [PATCH 2/3] Update
flang/test/Parser/continuation-in-conditional-compilation.f
Co-authored-by: Leandro Lupori <leandro.lupori at gmail.com>
---
flang/test/Parser/continuation-in-conditional-compilation.f | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/flang/test/Parser/continuation-in-conditional-compilation.f b/flang/test/Parser/continuation-in-conditional-compilation.f
index 92b74f089475b74..35eecbc0f16ea45 100644
--- a/flang/test/Parser/continuation-in-conditional-compilation.f
+++ b/flang/test/Parser/continuation-in-conditional-compilation.f
@@ -4,9 +4,9 @@ program main
k01=1+
!$ & 1
-! CHECK: !$omp parallel
-!$omp para
-!$omp+llel
+! CHECK: !$omp parallel private(k01)
+!$omp parallel
+!$omp+ private(k01)
!$omp end parallel
! CHECK-NOT: comment
>From f10d498b45b81e24e3924bded257b32df615f2a5 Mon Sep 17 00:00:00 2001
From: SiHuaN <liyongtai at iscas.ac.cn>
Date: Tue, 31 Oct 2023 11:27:33 +0800
Subject: [PATCH 3/3] restructure
---
flang/lib/Parser/prescan.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index de0d66a6bd50df2..430f3293f6c619c 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -997,15 +997,10 @@ const char *Prescanner::FixedFormContinuationLine(bool mightNeedSpace) {
}
tabInCurrentLine_ = false;
char col1{*nextLine_};
- if (InCompilerDirective() ||
- (features_.IsEnabled(LanguageFeature::OpenMP) &&
- IsFixedFormCommentChar(col1) && nextLine_[1] == '$')) {
+ if (IsFixedFormCommentChar(col1)) {
int j{1};
if (InCompilerDirective()) {
// Must be a continued compiler directive.
- if (!IsFixedFormCommentChar(col1)) {
- return nullptr;
- }
for (; j < 5; ++j) {
char ch{directiveSentinel_[j - 1]};
if (ch == '\0') {
@@ -1015,9 +1010,14 @@ const char *Prescanner::FixedFormContinuationLine(bool mightNeedSpace) {
return nullptr;
}
}
- } else {
+ } else if (features_.IsEnabled(LanguageFeature::OpenMP)) {
// Fixed Source Form Conditional Compilation Sentinels.
- j = 2;
+ if (nextLine_[1] != '$') {
+ return nullptr;
+ }
+ j++;
+ } else {
+ return nullptr;
}
for (; j < 5; ++j) {
if (nextLine_[j] != ' ') {
More information about the flang-commits
mailing list