Skip to content

Commit

Permalink
[flang][openmp] Handle !$INCLUDE "foo" (bug #64128)
Browse files Browse the repository at this point in the history
Detect and process INCLUDE lines that are guarded by OpenMP conditional
compilation markers (!$), when enabled.

Fixes #64128.

Differential Revision: https://reviews.llvm.org/D156759
  • Loading branch information
klausler committed Aug 1, 2023
1 parent 1e491c4 commit 2734f15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
27 changes: 14 additions & 13 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -153,6 +153,7 @@ void Prescanner::Statement() {
tokens.CloseToken();
}
break;
}
case LineClassification::Kind::Source:
BeginStatementAndAdvance();
if (inFixedForm_) {
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Parser/OpenMP/cond-include.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s
!CHECK: STOP "pass"
!$ include "cond-include.inc"
end
1 change: 1 addition & 0 deletions flang/test/Parser/OpenMP/cond-include.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STOP "pass"

0 comments on commit 2734f15

Please sign in to comment.