Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,17 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
// This is a Continuation line, not an initial directive line.
return std::nullopt;
}
++column, ++p;
}
if (isOpenMPConditional) {
for (; column <= fixedFormColumnLimit_; ++column, ++p) {
if (IsSpaceOrTab(p)) {
} else if (*p == '!') {
return std::nullopt; // !$ ! is a comment, not a directive
} else {
break;
}
}
}
if (const char *ss{IsCompilerDirectiveSentinel(
sentinel, static_cast<std::size_t>(sp - sentinel))}) {
Expand All @@ -1657,8 +1668,17 @@ Prescanner::IsFreeFormCompilerDirectiveLine(const char *start) const {
p && *p++ == '!') {
if (auto maybePair{IsCompilerDirectiveSentinel(p)}) {
auto offset{static_cast<std::size_t>(p - start - 1)};
return {LineClassification{LineClassification::Kind::CompilerDirective,
offset, maybePair->first}};
const char *sentinel{maybePair->first};
if ((sentinel[0] == '$' && sentinel[1] == '\0') || sentinel[1] == '@') {
if (const char *comment{IsFreeFormComment(maybePair->second)}) {
if (*comment == '!') {
// Conditional line comment - treat as comment
return std::nullopt;
}
}
}
return {LineClassification{
LineClassification::Kind::CompilerDirective, offset, sentinel}};
}
}
return std::nullopt;
Expand Down
1 change: 0 additions & 1 deletion flang/test/Preprocessing/bug136845.F
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*$1 continue
end

!PREPRO:!$ &
!PREPRO: continue
!PREPRO: k=0
!PREPRO: k=0
Expand Down
5 changes: 5 additions & 0 deletions flang/test/Preprocessing/cond-comment.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!RUN: %flang_fc1 -fopenmp -fdebug-unparse %s 2>&1 | FileCheck %s
!CHECK: END
!CHECK-NOT: error:
end
c$ !
5 changes: 5 additions & 0 deletions flang/test/Preprocessing/cond-comment.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!RUN: %flang_fc1 -fopenmp -fdebug-unparse %s 2>&1 | FileCheck %s
!CHECK: END
!CHECK-NOT: error:
end
!$ !