From 940efbde4012439532c01d89eafbb1d20e6b0dd4 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Mon, 17 Nov 2025 02:46:47 +0000 Subject: [PATCH] [Flang] [OpenMP] Add support for spaces in between the name Supports the fixed form syntax which has spaces in between the identifier --- flang/lib/Parser/prescan.cpp | 3 +++ flang/lib/Parser/prescan.h | 3 +++ flang/test/Parser/OpenMP/name-with-space.f | 15 +++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 flang/test/Parser/OpenMP/name-with-space.f 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