Skip to content

[flang] [Preprocessor] Fix ignoring OpenMP directive when preceded by a MACRO #140686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shivaramaarao
Copy link
Contributor

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

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels May 20, 2025
@llvmbot
Copy link
Member

llvmbot commented May 20, 2025

@llvm/pr-subscribers-flang-parser

Author: None (shivaramaarao)

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+1-1)
  • (added) flang/test/Preprocessing/bug117693.F90 (+14)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:parser flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] preprocessor removes OPENMP pragmas
2 participants