[flang-commits] [flang] 8b91de5 - [Flang][OpenMP] Correctly handling continuation lines with Fixed Source Form Conditional Compilation Sentinels (#70309)

via flang-commits flang-commits at lists.llvm.org
Tue Oct 31 18:05:37 PDT 2023


Author: SiHuaN
Date: 2023-11-01T09:05:33+08:00
New Revision: 8b91de5d6a3f98dcc00bbd286e339e512f7e3682

URL: https://github.com/llvm/llvm-project/commit/8b91de5d6a3f98dcc00bbd286e339e512f7e3682
DIFF: https://github.com/llvm/llvm-project/commit/8b91de5d6a3f98dcc00bbd286e339e512f7e3682.diff

LOG: [Flang][OpenMP] Correctly handling continuation lines with Fixed Source Form Conditional Compilation Sentinels (#70309)

Fixes #67947

---------

Co-authored-by: SiHuaN <liyongtai at iscas.ac.cn>
Co-authored-by: Leandro Lupori <leandro.lupori at gmail.com>

Added: 
    flang/test/Parser/continuation-in-conditional-compilation.f

Modified: 
    flang/lib/Parser/prescan.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 0408de6208647c9..1781cc8929f5611 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -1008,20 +1008,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 (IsFixedFormCommentChar(col1)) {
     int j{1};
-    for (; j < 5; ++j) {
-      char ch{directiveSentinel_[j - 1]};
-      if (ch == '\0') {
-        break;
+    if (InCompilerDirective()) {
+      // Must be a continued compiler directive.
+      for (; j < 5; ++j) {
+        char ch{directiveSentinel_[j - 1]};
+        if (ch == '\0') {
+          break;
+        }
+        if (ch != ToLowerCaseLetter(nextLine_[j])) {
+          return nullptr;
+        }
       }
-      if (ch != ToLowerCaseLetter(nextLine_[j])) {
+    } else if (features_.IsEnabled(LanguageFeature::OpenMP)) {
+      // Fixed Source Form Conditional Compilation Sentinels.
+      if (nextLine_[1] != '$') {
         return nullptr;
       }
+      j++;
+    } else {
+      return nullptr;
     }
     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..35eecbc0f16ea45
--- /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 private(k01)
+!$omp parallel
+!$omp+ private(k01)
+!$omp end parallel
+
+! CHECK-NOT: comment
+!$omp parallel
+!$acc+comment
+!$omp end parallel
+      end


        


More information about the flang-commits mailing list