[flang-commits] [flang] [flang] [Preprocessor] Fix ignoring OpenMP directive when preceded by a MACRO (PR #140686)

via flang-commits flang-commits at lists.llvm.org
Tue May 20 00:00:21 PDT 2025


https://github.com/shivaramaarao created https://github.com/llvm/llvm-project/pull/140686

When a macro is followed by OpenMP pragma it is considered as comment and ignored. The function IsCompilerDirectiveSentinel expects the compiler directive argument without the prefix comment character. This is fixed in this commit.

Fixes #117693

>From 74430527c4b73fa67327386a8476703d06edb3db Mon Sep 17 00:00:00 2001
From: Shivarama Rao <shivarama.rao at amd.com>
Date: Tue, 20 May 2025 06:48:52 +0000
Subject: [PATCH] When calling IsCompilerDirectiveSentinel,the prefix comment
 character need to be skipped.

Fixes #117693
---
 flang/lib/Parser/prescan.cpp           |  2 +-
 flang/test/Preprocessing/bug117693.F90 | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Preprocessing/bug117693.F90

diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 3bc2ea0b37508..2aeb2a81308cd 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -564,7 +564,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
     return true; // skip over ignored columns in right margin (73:80)
   } else if (*at_ == '!' && !inCharLiteral_ &&
       (!inFixedForm_ || tabInCurrentLine_ || column_ != 6)) {
-    return !IsCompilerDirectiveSentinel(at_);
+    return !IsCompilerDirectiveSentinel(at_ + 1);
   } else {
     return false;
   }
diff --git a/flang/test/Preprocessing/bug117693.F90 b/flang/test/Preprocessing/bug117693.F90
new file mode 100644
index 0000000000000..531c07417d0f1
--- /dev/null
+++ b/flang/test/Preprocessing/bug117693.F90
@@ -0,0 +1,14 @@
+! RUN: %flang -fopenmp -E %s 2>&1 | FileCheck %s
+! CHECK: !$OMP PARALLEL DO
+! CHECK: !$OMP END PARALLEL DO
+program main
+IMPLICIT NONE
+INTEGER:: I
+#define OMPSUPPORT
+INTEGER :: omp_id
+OMPSUPPORT !$OMP PARALLEL DO
+DO I=1,100
+print *, omp_id
+ENDDO
+OMPSUPPORT !$OMP END PARALLEL DO
+end program



More information about the flang-commits mailing list