Skip to content

[flang][openacc] Warn only when the same variable is in the same declare #70698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2023
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
27 changes: 20 additions & 7 deletions flang/lib/Semantics/check-acc-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,27 @@ void AccStructureChecker::CheckMultipleOccurrenceInDeclare(
[&](const Fortran::parser::Designator &designator) {
if (const auto *name = getDesignatorNameIfDataRef(designator)) {
if (declareSymbols.contains(&name->symbol->GetUltimate())) {
context_.Say(GetContext().clauseSource,
"'%s' in the %s clause is already present in another "
"clause in this module"_err_en_US,
name->symbol->name(),
parser::ToUpperCaseLetters(
llvm::acc::getOpenACCClauseName(clause).str()));
if (declareSymbols[&name->symbol->GetUltimate()] == clause) {
context_.Say(GetContext().clauseSource,
"'%s' in the %s clause is already present in the same "
"clause in this module"_warn_en_US,
name->symbol->name(),
parser::ToUpperCaseLetters(
llvm::acc::getOpenACCClauseName(clause).str()));
} else {
context_.Say(GetContext().clauseSource,
"'%s' in the %s clause is already present in another "
"%s clause in this module"_err_en_US,
name->symbol->name(),
parser::ToUpperCaseLetters(
llvm::acc::getOpenACCClauseName(clause).str()),
parser::ToUpperCaseLetters(
llvm::acc::getOpenACCClauseName(
declareSymbols[&name->symbol->GetUltimate()])
.str()));
}
}
declareSymbols.insert(&name->symbol->GetUltimate());
declareSymbols.insert({&name->symbol->GetUltimate(), clause});
}
},
[&](const Fortran::parser::Name &name) {
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Semantics/check-acc-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "flang/Common/enum-set.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Semantics/semantics.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Frontend/OpenACC/ACC.h.inc"

using AccDirectiveSet = Fortran::common::EnumSet<llvm::acc::Directive,
Expand Down Expand Up @@ -91,7 +91,7 @@ class AccStructureChecker
llvm::StringRef getClauseName(llvm::acc::Clause clause) override;
llvm::StringRef getDirectiveName(llvm::acc::Directive directive) override;

llvm::SmallDenseSet<Symbol *> declareSymbols;
llvm::SmallDenseMap<Symbol *, llvm::acc::Clause> declareSymbols;
unsigned loopNestLevel = 0;
};

Expand Down
7 changes: 5 additions & 2 deletions flang/test/Semantics/OpenACC/acc-declare-validity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module openacc_declare_validity

!$acc declare create(aa, bb)

!ERROR: 'aa' in the CREATE clause is already present in another clause in this module
!WARNING: 'aa' in the CREATE clause is already present in the same clause in this module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add an error check for case when it is in conflicting declare clause again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was on in the function but I added one back in the module declaration.

!$acc declare create(aa)

!$acc declare link(ab)
Expand All @@ -36,13 +36,16 @@ module openacc_declare_validity
!ERROR: The ZERO modifier is not allowed for the CREATE clause on the DECLARE directive
!$acc declare create(zero: dd)

!ERROR: 'bb' in the COPYIN clause is already present in another CREATE clause in this module
!$acc declare copyin(bb)

contains

subroutine sub1(cc, dd)
real(8) :: cc(:)
real(8) :: dd(:)
!$acc declare present(cc, dd)
!ERROR: 'cc' in the CREATE clause is already present in another clause in this module
!ERROR: 'cc' in the CREATE clause is already present in another PRESENT clause in this module
!$acc declare create(cc)
end subroutine sub1

Expand Down