[flang-commits] [flang] [Flang][OpenMP] Fix comments that should not be Sentinels on fixed format. (#68653) (PR #68911)

via flang-commits flang-commits at lists.llvm.org
Thu Oct 12 09:30:44 PDT 2023


https://github.com/Z572 created https://github.com/llvm/llvm-project/pull/68911

Fixes #68653


>From 97625313c4195cd3fab0594c84252d9664b0b078 Mon Sep 17 00:00:00 2001
From: Zheng Junjie <zhengjunjie at iscas.ac.cn>
Date: Thu, 12 Oct 2023 17:58:29 +0800
Subject: [PATCH] [Flang][OpenMP] Fix comments that should not be Sentinels on
 fixed format. (#68653)

---
 flang/lib/Parser/prescan.cpp         |  9 +++++----
 flang/test/Parser/OpenMP/sentinels.f | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Parser/OpenMP/sentinels.f

diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 2f25b02bf7a323d..645e0bc525be08d 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -1174,6 +1174,9 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
   if (!IsFixedFormCommentChar(col1)) {
     return std::nullopt;
   }
+  if (p[0] != '$'){
+    return std::nullopt;
+  };
   char sentinel[5], *sp{sentinel};
   int column{2};
   for (; column < 6; ++column, ++p) {
@@ -1181,11 +1184,9 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
       if (*p == '\n' || *p == '\t') {
         break;
       }
-      if (sp == sentinel + 1 && sentinel[0] == '$' && IsDecimalDigit(*p)) {
-        // OpenMP conditional compilation line: leave the label alone
-        break;
+      if (!IsDecimalDigit(*p)){
+        *sp++ = ToLowerCaseLetter(*p);
       }
-      *sp++ = ToLowerCaseLetter(*p);
     }
   }
   if (column == 6) {
diff --git a/flang/test/Parser/OpenMP/sentinels.f b/flang/test/Parser/OpenMP/sentinels.f
new file mode 100644
index 000000000000000..f70597ea6a5203b
--- /dev/null
+++ b/flang/test/Parser/OpenMP/sentinels.f
@@ -0,0 +1,24 @@
+! RUN: %flang_fc1 -fopenmp -E %s | FileCheck %s
+! CHECK:      program main
+! CHECK:      print *, "Is '    '"
+! CHECK:  123 print *, "Is '123 '"
+! CHECK:      end
+
+      program main
+!$    print *, "Is '    '"
+!$123 print *, "Is '123 '"
+!$1234print *, "This is a comment line"
+!$ABC print *, "This is a comment line"
+! $    print *, "This is a comment line"
+c    $This is a comment line
+!0$110This is a comment line
+
+! $ This is a comment line
+! $  0This is a comment line
+!    &This is a comment line
+!  $  This is a comment line
+! $   This is a comment line
+C $   This is a comment line
+c $   his is a comment line
+* $   This is a comment line
+      end



More information about the flang-commits mailing list