[flang-commits] [flang] [flang][openacc] Warn only when the same variable is in the same declare (PR #70698)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Mon Oct 30 14:29:24 PDT 2023
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/70698
>From b8fb3c4ed22d7c70f74dd096e55e104d4a58db11 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 30 Oct 2023 11:06:03 -0700
Subject: [PATCH 1/2] [flang][openacc] Warn only when the same variable is in
the same declare clause
---
flang/lib/Semantics/check-acc-structure.cpp | 23 +++++++++++++------
flang/lib/Semantics/check-acc-structure.h | 4 ++--
.../OpenACC/acc-declare-validity.f90 | 2 +-
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 763418ede24d5a7..d14098e09a8f0e8 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -401,14 +401,23 @@ 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 "
+ "clause in this module"_err_en_US,
+ name->symbol->name(),
+ parser::ToUpperCaseLetters(
+ llvm::acc::getOpenACCClauseName(clause).str()));
+ }
}
- declareSymbols.insert(&name->symbol->GetUltimate());
+ declareSymbols.insert({&name->symbol->GetUltimate(), clause});
}
},
[&](const Fortran::parser::Name &name) {
diff --git a/flang/lib/Semantics/check-acc-structure.h b/flang/lib/Semantics/check-acc-structure.h
index 2a09b7a39395d16..6a9aa01a9bb1333 100644
--- a/flang/lib/Semantics/check-acc-structure.h
+++ b/flang/lib/Semantics/check-acc-structure.h
@@ -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,
@@ -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;
};
diff --git a/flang/test/Semantics/OpenACC/acc-declare-validity.f90 b/flang/test/Semantics/OpenACC/acc-declare-validity.f90
index c0333d78dd9f78b..6907e17919c93e3 100644
--- a/flang/test/Semantics/OpenACC/acc-declare-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-declare-validity.f90
@@ -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
!$acc declare create(aa)
!$acc declare link(ab)
>From 8e6130770a3dabda0958716f56fd265663fccc1b Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 30 Oct 2023 14:28:53 -0700
Subject: [PATCH 2/2] Add error test and update message
---
flang/lib/Semantics/check-acc-structure.cpp | 8 ++++++--
flang/test/Semantics/OpenACC/acc-declare-validity.f90 | 5 ++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index d14098e09a8f0e8..64b07da2324d970 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -411,10 +411,14 @@ void AccStructureChecker::CheckMultipleOccurrenceInDeclare(
} else {
context_.Say(GetContext().clauseSource,
"'%s' in the %s clause is already present in another "
- "clause in this module"_err_en_US,
+ "%s clause in this module"_err_en_US,
name->symbol->name(),
parser::ToUpperCaseLetters(
- llvm::acc::getOpenACCClauseName(clause).str()));
+ llvm::acc::getOpenACCClauseName(clause).str()),
+ parser::ToUpperCaseLetters(
+ llvm::acc::getOpenACCClauseName(
+ declareSymbols[&name->symbol->GetUltimate()])
+ .str()));
}
}
declareSymbols.insert({&name->symbol->GetUltimate(), clause});
diff --git a/flang/test/Semantics/OpenACC/acc-declare-validity.f90 b/flang/test/Semantics/OpenACC/acc-declare-validity.f90
index 6907e17919c93e3..2e7e651815d4a3a 100644
--- a/flang/test/Semantics/OpenACC/acc-declare-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-declare-validity.f90
@@ -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
More information about the flang-commits
mailing list