[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
Mon Dec 23 01:59:31 PST 2024
https://github.com/Karthikdhondi updated https://github.com/llvm/llvm-project/pull/120714
>From 9651ab4b42f9bdfe1a7862da34cfb600247c0f79 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] [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
+
More information about the flang-commits
mailing list