[flang-commits] [flang] [FLANG][OPENMP] Fix handling of continuation lines in mixed OpenMP an… (PR #120714)
via flang-commits
flang-commits at lists.llvm.org
Thu Dec 26 05:56:01 PST 2024
https://github.com/Karthikdhondi updated https://github.com/llvm/llvm-project/pull/120714
>From 07d669ea085742f7fdcdc16bc4896c1ee33f9bfc Mon Sep 17 00:00:00 2001
From: karthikdhondi <karthik.dhondi at gmail.com>
Date: Fri, 20 Dec 2024 16:11:39 +0530
Subject: [PATCH 1/4] [FLANG][OPENMP] Fix handling of continuation lines in
mixed OpenMP and Fortran free-form
---
flang/lib/Parser/prescan.cpp | 50 +++++++++++++++-------
flang/test/Parser/cd_continuation.f90 | 61 +++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 15 deletions(-)
create mode 100644 flang/test/Parser/cd_continuation.f90
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 3cd32d7e6c92e8..d5bde4b55c7b2a 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -1289,29 +1289,49 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
return nullptr;
}
p = SkipWhiteSpace(p);
- if (InCompilerDirective()) {
- if (*p++ != '!') {
- return nullptr;
- }
- for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
- if (*s != ToLowerCaseLetter(*p)) {
+ if (*p == '!') {
+ if (InCompilerDirective()) {
+ if (*p++ != '!') {
return nullptr;
}
- }
- p = SkipWhiteSpace(p);
- if (*p == '&') {
- if (!ampersand) {
- insertASpace_ = true;
+ for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
+ if (*s != ToLowerCaseLetter(*p)) {
+ return nullptr;
+ }
+ }
+ p = SkipWhiteSpace(p);
+ if (*p == '&') {
+ if (!ampersand) {
+ insertASpace_ = true;
+ }
+ return p + 1;
+ } else if (ampersand) {
+ return p;
+ } else {
+ return nullptr;
+ }
+ } else if (features_.IsEnabled(LanguageFeature::OpenMP)) {
+ if (*p + 1 == '$')
+ return nullptr;
+ p += 2;
+ p = SkipWhiteSpace(p);
+ if (*p == '&') {
+ if (!ampersand) {
+ insertASpace_ = true;
+ }
+ return p + 1;
+ } else if (ampersand) {
+ return p;
+ } else {
+ return nullptr;
}
- return p + 1;
- } else if (ampersand) {
- return p;
} else {
return nullptr;
}
} else {
if (*p == '&') {
- return p + 1;
+ p = SkipWhiteSpace(p + 1);
+ return p;
} else if (*p == '!' || *p == '\n' || *p == '#') {
return nullptr;
} else if (ampersand || IsImplicitContinuation()) {
diff --git a/flang/test/Parser/cd_continuation.f90 b/flang/test/Parser/cd_continuation.f90
new file mode 100644
index 00000000000000..c16deae19447f5
--- /dev/null
+++ b/flang/test/Parser/cd_continuation.f90
@@ -0,0 +1,61 @@
+! RUN: flang-new -fopenmp -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-OMP
+! RUN: flang-new -E %s 2>&1 | FileCheck %s
+
+
+! Test in mixed way, i.e., combination of Fortran free source form
+! and free source form with conditional compilation sentinel.
+! CHECK-LABEL: subroutine mixed_form1()
+! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
+! CHECK: i = 1 + 10 + 10000 + 1000000
+subroutine mixed_form1()
+ i = 1 &
+ !$+100&
+ !$&+ 1000&
+ &+ 10 + 1&
+ !$& +100000&
+ &0000 + 1000000
+end subroutine
+
+
+
+! CHECK-LABEL: subroutine mixed_form2()
+! CHECK-OMP: i = 0
+! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
+! CHECK: i = 1 + 10 + 10000 + 1000000
+subroutine mixed_form2()
+!$ i = 0
+ i = 1 &
+ !$+100&
+ !$&+ 1000&
+ &+ 10 + 1&
+ !$& +100000&
+ & 0000 + 1000000
+
+end subroutine
+
+
+! Testing continuation lines in only Fortran Free form Source
+! CHECK-LABEL: subroutine mixed_form3()
+! CHECK-OMP: i = 1 +10 +100+ 1000 + 10000
+! CHECK: i = 1 +10 +100+ 1000 + 10000
+subroutine mixed_form3()
+ i = 1 &
+ +10 &
+ &+100
+ & + 1000 &
+ + 10000
+end subroutine
+
+
+! Testing continuation line in only free source form conditional compilation sentinel.
+! CHECK-LABEL: subroutine mixed_form4()
+! CHECK-OMP: i=0
+! CHECK-OMP: i = 1 +10 +100+1000
+subroutine mixed_form4()
+ !$ i=0
+ !$ i = 1 &
+ !$ & +10 &
+ !$&+100&
+ !$ +1000
+end subroutine
+
>From 11aca6aa3328b1dffc48c85cc88d91bb439aafb1 Mon Sep 17 00:00:00 2001
From: karthikdhondi <karthik.dhondi at gmail.com>
Date: Tue, 24 Dec 2024 18:47:59 +0530
Subject: [PATCH 2/4] Reorganized code to eliminate repeated ampersand logic
and removed whitespace skipping.
---
....f90 => compiler-directive_continuation.f90} | 17 -----------------
1 file changed, 17 deletions(-)
rename flang/test/Parser/{cd_continuation.f90 => compiler-directive_continuation.f90} (78%)
diff --git a/flang/test/Parser/cd_continuation.f90 b/flang/test/Parser/compiler-directive_continuation.f90
similarity index 78%
rename from flang/test/Parser/cd_continuation.f90
rename to flang/test/Parser/compiler-directive_continuation.f90
index c16deae19447f5..e2ad14c7e57f8f 100644
--- a/flang/test/Parser/cd_continuation.f90
+++ b/flang/test/Parser/compiler-directive_continuation.f90
@@ -17,23 +17,6 @@ subroutine mixed_form1()
end subroutine
-
-! CHECK-LABEL: subroutine mixed_form2()
-! CHECK-OMP: i = 0
-! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
-! CHECK: i = 1 + 10 + 10000 + 1000000
-subroutine mixed_form2()
-!$ i = 0
- i = 1 &
- !$+100&
- !$&+ 1000&
- &+ 10 + 1&
- !$& +100000&
- & 0000 + 1000000
-
-end subroutine
-
-
! Testing continuation lines in only Fortran Free form Source
! CHECK-LABEL: subroutine mixed_form3()
! CHECK-OMP: i = 1 +10 +100+ 1000 + 10000
>From 9fc66460fa3cfe02d5976201797ef3b9638ad900 Mon Sep 17 00:00:00 2001
From: karthikdhondi <karthik.dhondi at gmail.com>
Date: Fri, 20 Dec 2024 16:11:39 +0530
Subject: [PATCH 3/4] [FLANG][OPENMP] Fix handling of continuation lines in
mixed OpenMP and Fortran free-form
---
flang/test/Parser/cd_continuation.f90 | 61 +++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 flang/test/Parser/cd_continuation.f90
diff --git a/flang/test/Parser/cd_continuation.f90 b/flang/test/Parser/cd_continuation.f90
new file mode 100644
index 00000000000000..c16deae19447f5
--- /dev/null
+++ b/flang/test/Parser/cd_continuation.f90
@@ -0,0 +1,61 @@
+! RUN: flang-new -fopenmp -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-OMP
+! RUN: flang-new -E %s 2>&1 | FileCheck %s
+
+
+! Test in mixed way, i.e., combination of Fortran free source form
+! and free source form with conditional compilation sentinel.
+! CHECK-LABEL: subroutine mixed_form1()
+! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
+! CHECK: i = 1 + 10 + 10000 + 1000000
+subroutine mixed_form1()
+ i = 1 &
+ !$+100&
+ !$&+ 1000&
+ &+ 10 + 1&
+ !$& +100000&
+ &0000 + 1000000
+end subroutine
+
+
+
+! CHECK-LABEL: subroutine mixed_form2()
+! CHECK-OMP: i = 0
+! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
+! CHECK: i = 1 + 10 + 10000 + 1000000
+subroutine mixed_form2()
+!$ i = 0
+ i = 1 &
+ !$+100&
+ !$&+ 1000&
+ &+ 10 + 1&
+ !$& +100000&
+ & 0000 + 1000000
+
+end subroutine
+
+
+! Testing continuation lines in only Fortran Free form Source
+! CHECK-LABEL: subroutine mixed_form3()
+! CHECK-OMP: i = 1 +10 +100+ 1000 + 10000
+! CHECK: i = 1 +10 +100+ 1000 + 10000
+subroutine mixed_form3()
+ i = 1 &
+ +10 &
+ &+100
+ & + 1000 &
+ + 10000
+end subroutine
+
+
+! Testing continuation line in only free source form conditional compilation sentinel.
+! CHECK-LABEL: subroutine mixed_form4()
+! CHECK-OMP: i=0
+! CHECK-OMP: i = 1 +10 +100+1000
+subroutine mixed_form4()
+ !$ i=0
+ !$ i = 1 &
+ !$ & +10 &
+ !$&+100&
+ !$ +1000
+end subroutine
+
>From 15b310834ff7237a4ea6b44bf765e471aad6c3f2 Mon Sep 17 00:00:00 2001
From: karthikdhondi <karthik.dhondi at gmail.com>
Date: Thu, 26 Dec 2024 17:46:38 +0530
Subject: [PATCH 4/4] Reorganized code to eliminate repeated ampersand logic
and removed whitespace skipping.
---
flang/lib/Parser/prescan.cpp | 42 ++++++------------
flang/test/Parser/cd_continuation.f90 | 61 ---------------------------
2 files changed, 13 insertions(+), 90 deletions(-)
delete mode 100644 flang/test/Parser/cd_continuation.f90
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index d5bde4b55c7b2a..fa51f2ae8218a4 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -1290,48 +1290,32 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
}
p = SkipWhiteSpace(p);
if (*p == '!') {
+ ++p;
if (InCompilerDirective()) {
- if (*p++ != '!') {
- return nullptr;
- }
for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
if (*s != ToLowerCaseLetter(*p)) {
return nullptr;
}
}
- p = SkipWhiteSpace(p);
- if (*p == '&') {
- if (!ampersand) {
- insertASpace_ = true;
- }
- return p + 1;
- } else if (ampersand) {
- return p;
- } else {
- return nullptr;
- }
} else if (features_.IsEnabled(LanguageFeature::OpenMP)) {
- if (*p + 1 == '$')
- return nullptr;
- p += 2;
- p = SkipWhiteSpace(p);
- if (*p == '&') {
- if (!ampersand) {
- insertASpace_ = true;
- }
- return p + 1;
- } else if (ampersand) {
- return p;
- } else {
- return nullptr;
+ ++p;
+ } else {
+ return nullptr;
+ }
+ p = SkipWhiteSpace(p);
+ if (*p == '&') {
+ if (!ampersand) {
+ insertASpace_ = true;
}
+ return p + 1;
+ } else if (ampersand) {
+ return p;
} else {
return nullptr;
}
} else {
if (*p == '&') {
- p = SkipWhiteSpace(p + 1);
- return p;
+ return p + 1;
} else if (*p == '!' || *p == '\n' || *p == '#') {
return nullptr;
} else if (ampersand || IsImplicitContinuation()) {
diff --git a/flang/test/Parser/cd_continuation.f90 b/flang/test/Parser/cd_continuation.f90
deleted file mode 100644
index c16deae19447f5..00000000000000
--- a/flang/test/Parser/cd_continuation.f90
+++ /dev/null
@@ -1,61 +0,0 @@
-! RUN: flang-new -fopenmp -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-OMP
-! RUN: flang-new -E %s 2>&1 | FileCheck %s
-
-
-! Test in mixed way, i.e., combination of Fortran free source form
-! and free source form with conditional compilation sentinel.
-! CHECK-LABEL: subroutine mixed_form1()
-! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
-! CHECK: i = 1 + 10 + 10000 + 1000000
-subroutine mixed_form1()
- i = 1 &
- !$+100&
- !$&+ 1000&
- &+ 10 + 1&
- !$& +100000&
- &0000 + 1000000
-end subroutine
-
-
-
-! CHECK-LABEL: subroutine mixed_form2()
-! CHECK-OMP: i = 0
-! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
-! CHECK: i = 1 + 10 + 10000 + 1000000
-subroutine mixed_form2()
-!$ i = 0
- i = 1 &
- !$+100&
- !$&+ 1000&
- &+ 10 + 1&
- !$& +100000&
- & 0000 + 1000000
-
-end subroutine
-
-
-! Testing continuation lines in only Fortran Free form Source
-! CHECK-LABEL: subroutine mixed_form3()
-! CHECK-OMP: i = 1 +10 +100+ 1000 + 10000
-! CHECK: i = 1 +10 +100+ 1000 + 10000
-subroutine mixed_form3()
- i = 1 &
- +10 &
- &+100
- & + 1000 &
- + 10000
-end subroutine
-
-
-! Testing continuation line in only free source form conditional compilation sentinel.
-! CHECK-LABEL: subroutine mixed_form4()
-! CHECK-OMP: i=0
-! CHECK-OMP: i = 1 +10 +100+1000
-subroutine mixed_form4()
- !$ i=0
- !$ i = 1 &
- !$ & +10 &
- !$&+100&
- !$ +1000
-end subroutine
-
More information about the flang-commits
mailing list