-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[flang] Fix issue when macro is followed by OpenMP pragma #123035
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
Conversation
|
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 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. |
|
@llvm/pr-subscribers-flang-parser Author: None (shivaramaarao) ChangesWhen 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/123035.diff 2 Files Affected:
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index c5939a1e0b6c2c..50a9193d0a57b3 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -511,7 +511,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
if (inFixedForm_ && column_ > fixedFormColumnLimit_ && !tabInCurrentLine_) {
return true; // skip over ignored columns in right margin (73:80)
} else if (*at_ == '!' && !inCharLiteral_) {
- 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 00000000000000..ced7927606e623
--- /dev/null
+++ b/flang/test/Preprocessing/bug117693.f90
@@ -0,0 +1,14 @@
+! RUN: %flang -fopenmp -E %s 2>&1 | FileCheck %s
+!CHECK: !$OMP DO SCHEDULE(STATIC)
+program main
+IMPLICIT NONE
+INTEGER:: I
+#define OMPSUPPORT
+!$ INTEGER :: omp_id
+!$OMP PARALLEL DO
+OMPSUPPORT !$OMP DO SCHEDULE(STATIC)
+DO I=1,100
+print *, omp_id
+ENDDO
+!$OMP END PARALLEL DO
+end program
|
You can test this locally with the following command:git-clang-format --diff eb96c8c105226956c8ed5ab30699206f53de74f7 bfc3d201256ecbdc77402758dae955048384ef78 --extensions cpp -- flang/lib/Parser/prescan.cppView the diff from clang-format here.diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 50a9193d0a..b928ed03a2 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -511,7 +511,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
if (inFixedForm_ && column_ > fixedFormColumnLimit_ && !tabInCurrentLine_) {
return true; // skip over ignored columns in right margin (73:80)
} else if (*at_ == '!' && !inCharLiteral_) {
- return !IsCompilerDirectiveSentinel(at_+1);
+ return !IsCompilerDirectiveSentinel(at_ + 1);
} else {
return false;
}
|
|
I am seeing a side effect with this change. program main The comment is not getting ignored by the preprocessor. |
|
I do see more cases to be handled. currently for the source lines that begins with MACRO, characters after "!" are discarded and many issues are hidden. When I was looking into the code, I feel we might need to make design changes to existing implementation that handles macro replacement to consider all these cases. Can someone please comment on this? |
|
The recent pull request addresses the issue with comments and continuation lines. The conditional compilation issue will be addressed as separate pull request. |
|
Is the PR ok to submit? If So, I can ask some of our AMD engineers to commit and we will follow up on any regressions. |
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