[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
Fri Oct 27 01:26:38 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] [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



More information about the flang-commits mailing list