[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:01:17 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: None (shivaramaarao)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/140686
More information about the flang-commits
mailing list