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
26 changes: 9 additions & 17 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,9 @@ void Prescanner::Statement() {
CHECK(*at_ == '!');
}
std::optional<int> condOffset;
if (InOpenMPConditionalLine()) {
if (InOpenMPConditionalLine()) { // !$
condOffset = 2;
} else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'c' &&
directiveSentinel_[2] == 'u' && directiveSentinel_[3] == 'f' &&
directiveSentinel_[4] == '\0') {
// CUDA conditional compilation line.
condOffset = 5;
} else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'a' &&
directiveSentinel_[2] == 'c' && directiveSentinel_[3] == 'c' &&
directiveSentinel_[4] == '\0') {
// OpenACC conditional compilation line.
} else if (InOpenACCOrCUDAConditionalLine()) { // !@acc or !@cuf
condOffset = 5;
}
if (condOffset && !preprocessingOnly_) {
Expand All @@ -166,7 +158,8 @@ void Prescanner::Statement() {
} else {
// Compiler directive. Emit normalized sentinel, squash following spaces.
// Conditional compilation lines (!$) take this path in -E mode too
// so that -fopenmp only has to appear on the later compilation.
// so that -fopenmp only has to appear on the later compilation
// (ditto for !@cuf and !@acc).
EmitChar(tokens, '!');
++at_, ++column_;
for (const char *sp{directiveSentinel_}; *sp != '\0';
Expand Down Expand Up @@ -202,7 +195,7 @@ void Prescanner::Statement() {
}
tokens.CloseToken();
SkipSpaces();
if (InOpenMPConditionalLine() && inFixedForm_ && !tabInCurrentLine_ &&
if (InConditionalLine() && inFixedForm_ && !tabInCurrentLine_ &&
column_ == 6 && *at_ != '\n') {
// !$ 0 - turn '0' into a space
// !$ 1 - turn '1' into '&'
Expand Down Expand Up @@ -347,7 +340,7 @@ void Prescanner::Statement() {
while (CompilerDirectiveContinuation(tokens, line.sentinel)) {
newlineProvenance = GetCurrentProvenance();
}
if (preprocessingOnly_ && inFixedForm_ && InOpenMPConditionalLine() &&
if (preprocessingOnly_ && inFixedForm_ && InConditionalLine() &&
nextLine_ < limit_) {
// In -E mode, when the line after !$ conditional compilation is a
// regular fixed form continuation line, append a '&' to the line.
Expand Down Expand Up @@ -1360,11 +1353,10 @@ const char *Prescanner::FixedFormContinuationLine(bool atNewline) {
features_.IsEnabled(LanguageFeature::OldDebugLines))) &&
nextLine_[1] == ' ' && nextLine_[2] == ' ' && nextLine_[3] == ' ' &&
nextLine_[4] == ' '};
if (InCompilerDirective() &&
!(InOpenMPConditionalLine() && !preprocessingOnly_)) {
if (InCompilerDirective() && !(InConditionalLine() && !preprocessingOnly_)) {
// !$ under -E is not continued, but deferred to later compilation
if (IsFixedFormCommentChar(col1) &&
!(InOpenMPConditionalLine() && preprocessingOnly_)) {
!(InConditionalLine() && preprocessingOnly_)) {
int j{1};
for (; j < 5; ++j) {
char ch{directiveSentinel_[j - 1]};
Expand Down Expand Up @@ -1443,7 +1435,7 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
}
p = SkipWhiteSpaceIncludingEmptyMacros(p);
if (InCompilerDirective()) {
if (InOpenMPConditionalLine()) {
if (InConditionalLine()) {
if (preprocessingOnly_) {
// in -E mode, don't treat !$ as a continuation
return nullptr;
Expand Down
12 changes: 11 additions & 1 deletion flang/lib/Parser/prescan.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,17 @@ class Prescanner {
bool InOpenMPConditionalLine() const {
return directiveSentinel_ && directiveSentinel_[0] == '$' &&
!directiveSentinel_[1];
;
}
bool InOpenACCOrCUDAConditionalLine() const {
return directiveSentinel_ && directiveSentinel_[0] == '@' &&
((directiveSentinel_[1] == 'a' && directiveSentinel_[2] == 'c' &&
directiveSentinel_[3] == 'c') ||
(directiveSentinel_[1] == 'c' && directiveSentinel_[2] == 'u' &&
directiveSentinel_[3] == 'f')) &&
directiveSentinel_[4] == '\0';
}
bool InConditionalLine() const {
return InOpenMPConditionalLine() || InOpenACCOrCUDAConditionalLine();
}
bool InFixedFormSource() const {
return inFixedForm_ && !inPreprocessorDirective_ && !InCompilerDirective();
Expand Down
6 changes: 6 additions & 0 deletions flang/test/Preprocessing/bug164470.cuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!RUN: %flang_fc1 -x cuda -fdebug-unparse %s 2>&1 | FileCheck %s
!CHECK: ATTRIBUTES(DEVICE) FUNCTION foo()
!@cuf attributes(device) &
function foo()
foo = 1.
end