[flang] Treat conditional comments as comments (#165881)
An OpenMP, OpenACC, or CUDA conditional line should be treated as a comment when that's what its payload contains, not as a conditional source line that will confuse the parser when it is indeed just a comment.
This commit is contained in:
parent
2abcb19af2
commit
77cd34eedf
4 changed files with 32 additions and 3 deletions
|
|
@ -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))}) {
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ c$ !1 B
|
|||
*$1 continue
|
||||
end
|
||||
|
||||
!PREPRO:!$ &
|
||||
!PREPRO: continue
|
||||
!PREPRO: k=0
|
||||
!PREPRO: k=0
|
||||
|
|
|
|||
5
flang/test/Preprocessing/cond-comment.f
Normal file
5
flang/test/Preprocessing/cond-comment.f
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
!RUN: %flang_fc1 -fopenmp -fdebug-unparse %s 2>&1 | FileCheck %s
|
||||
!CHECK: END
|
||||
!CHECK-NOT: error:
|
||||
end
|
||||
c$ !
|
||||
5
flang/test/Preprocessing/cond-comment.f90
Normal file
5
flang/test/Preprocessing/cond-comment.f90
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
!RUN: %flang_fc1 -fopenmp -fdebug-unparse %s 2>&1 | FileCheck %s
|
||||
!CHECK: END
|
||||
!CHECK-NOT: error:
|
||||
end
|
||||
!$ !
|
||||
Loading…
Reference in a new issue