Skip to content

Conversation

@Thirumalai-Shaktivel
Copy link
Member

Supports the fixed form syntax which has spaces in between the identifier

Supports the fixed form syntax which has spaces
in between the identifier
@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-parser

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Changes

Supports the fixed form syntax which has spaces in between the identifier


Full diff: https://github.com/llvm/llvm-project/pull/168311.diff

3 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+3)
  • (modified) flang/lib/Parser/prescan.h (+3)
  • (added) flang/test/Parser/OpenMP/name-with-space.f (+15)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 8cccd84f9fa19..5e8d50be277a0 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -845,6 +845,9 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
     if (InFixedFormSource()) {
       SkipSpaces();
     }
+    if (inFixedForm_ && (IsOpenMPDirective() && parenthesisNesting_ > 0)) {
+      SkipSpaces();
+    }
     if ((*at_ == '\'' || *at_ == '"') &&
         tokens.CharAt(tokens.SizeInChars() - 1) == '_') { // kind_"..."
       QuotedCharacterLiteral(tokens, start);
diff --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h
index 5e7481781d944..4f691d56975a9 100644
--- a/flang/lib/Parser/prescan.h
+++ b/flang/lib/Parser/prescan.h
@@ -183,6 +183,9 @@ class Prescanner {
   bool InConditionalLine() const {
     return InOpenMPConditionalLine() || InOpenACCOrCUDAConditionalLine();
   }
+  bool IsOpenMPDirective() const {
+    return directiveSentinel_ && std::strcmp(directiveSentinel_, "$omp") == 0;
+  }
   bool InFixedFormSource() const {
     return inFixedForm_ && !inPreprocessorDirective_ && !InCompilerDirective();
   }
diff --git a/flang/test/Parser/OpenMP/name-with-space.f b/flang/test/Parser/OpenMP/name-with-space.f
new file mode 100644
index 0000000000000..603ebc40c9f4c
--- /dev/null
+++ b/flang/test/Parser/OpenMP/name-with-space.f
@@ -0,0 +1,15 @@
+! RUN: %flang_fc1 -fopenmp -fdebug-unparse-no-sema %s 2>&1 | FileCheck %s
+
+        program name_with_space
+!CHECK: !$OMP THREADPRIVATE(/cc/, var1)
+!$omp threadprivate(/c c/, var 1)
+
+!CHECK: !$OMP PARALLEL PRIVATE(somevar,expr1,expr2) IF(expr2>expr1)
+!$omp parallel private(some var, expr 1, ex pr2)
+!$omp+ if (exp r2 > ex pr1)
+!$omp critical (x_x)
+        print '(a)', 'Hello World'
+!CHECK: !$OMP END CRITICAL(x_x)
+!$omp end critical (x _x)
+!$omp end parallel
+        end program name_with_space

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Thirumalai-Shaktivel
Copy link
Member Author

Thanks for the review!

@Thirumalai-Shaktivel Thirumalai-Shaktivel merged commit 38811be into llvm:main Nov 17, 2025
14 checks passed
@Thirumalai-Shaktivel Thirumalai-Shaktivel deleted the llvm/prescan_01 branch November 17, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:openmp flang:parser flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants