[flang-commits] [flang] 2734f15 - [flang][openmp] Handle !$INCLUDE "foo" (bug #64128)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Aug 1 11:35:45 PDT 2023
Author: Peter Klausler
Date: 2023-08-01T11:35:23-07:00
New Revision: 2734f15437b67343d594c377c00cb2c3cf1d2f86
URL: https://github.com/llvm/llvm-project/commit/2734f15437b67343d594c377c00cb2c3cf1d2f86
DIFF: https://github.com/llvm/llvm-project/commit/2734f15437b67343d594c377c00cb2c3cf1d2f86.diff
LOG: [flang][openmp] Handle !$INCLUDE "foo" (bug #64128)
Detect and process INCLUDE lines that are guarded by OpenMP conditional
compilation markers (!$), when enabled.
Fixes https://github.com/llvm/llvm-project/issues/64128.
Differential Revision: https://reviews.llvm.org/D156759
Added:
flang/test/Parser/OpenMP/cond-include.f90
flang/test/Parser/OpenMP/cond-include.inc
Modified:
flang/lib/Parser/prescan.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index f9f94bbe62f46f..37ac1e5f4ecec8 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -106,7 +106,7 @@ void Prescanner::Statement() {
case LineClassification::Kind::PreprocessorDirective:
preprocessor_.Directive(TokenizePreprocessorDirective(), *this);
return;
- case LineClassification::Kind::CompilerDirective:
+ case LineClassification::Kind::CompilerDirective: {
directiveSentinel_ = line.sentinel;
CHECK(InCompilerDirective());
BeginStatementAndAdvance();
@@ -118,22 +118,22 @@ void Prescanner::Statement() {
}
CHECK(*at_ == '!');
}
+ std::optional<int> condOffset;
if (directiveSentinel_[0] == '$' && directiveSentinel_[1] == '\0') {
- // OpenMP conditional compilation line. Remove the sentinel and then
- // treat the line as if it were normal source.
- at_ += 2, column_ += 2;
- if (inFixedForm_) {
- LabelField(tokens);
- } else {
- SkipSpaces();
- }
+ // OpenMP conditional compilation line.
+ condOffset = 2;
} else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'c' &&
directiveSentinel_[2] == 'u' && directiveSentinel_[3] == 'f' &&
directiveSentinel_[4] == '\0') {
- // CUDA conditional compilation line. Remove the sentinel and then
- // treat the line as if it were normal source.
- at_ += 5, column_ += 5;
- if (inFixedForm_) {
+ // CUDA conditional compilation line.
+ condOffset = 5;
+ }
+ if (condOffset) {
+ at_ += *condOffset, column_ += *condOffset;
+ if (auto payload{IsIncludeLine(at_)}) {
+ FortranInclude(at_ + *payload);
+ return;
+ } else if (inFixedForm_) {
LabelField(tokens);
} else {
SkipSpaces();
@@ -153,6 +153,7 @@ void Prescanner::Statement() {
tokens.CloseToken();
}
break;
+ }
case LineClassification::Kind::Source:
BeginStatementAndAdvance();
if (inFixedForm_) {
diff --git a/flang/test/Parser/OpenMP/cond-include.f90 b/flang/test/Parser/OpenMP/cond-include.f90
new file mode 100644
index 00000000000000..06a6b4380c7ce5
--- /dev/null
+++ b/flang/test/Parser/OpenMP/cond-include.f90
@@ -0,0 +1,4 @@
+! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s
+!CHECK: STOP "pass"
+!$ include "cond-include.inc"
+end
diff --git a/flang/test/Parser/OpenMP/cond-include.inc b/flang/test/Parser/OpenMP/cond-include.inc
new file mode 100644
index 00000000000000..15cbdc95954c9f
--- /dev/null
+++ b/flang/test/Parser/OpenMP/cond-include.inc
@@ -0,0 +1 @@
+STOP "pass"
More information about the flang-commits
mailing list