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
45 changes: 36 additions & 9 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "llvm/Support/Debug.h"
#include <list>
#include <map>
#include <sstream>

template <typename T>
static Fortran::semantics::Scope *GetScope(
Expand Down Expand Up @@ -61,6 +60,13 @@ template <typename T> class DirectiveAttributeVisitor {
parser::OmpDefaultmapClause::ImplicitBehavior>
defaultMap;

std::optional<Symbol::Flag> FindSymbolWithDSA(const Symbol &symbol) {
if (auto it{objectWithDSA.find(&symbol)}; it != objectWithDSA.end()) {
return it->second;
}
return std::nullopt;
}

bool withinConstruct{false};
std::int64_t associatedLoopLevel{0};
};
Expand All @@ -75,10 +81,19 @@ template <typename T> class DirectiveAttributeVisitor {
: std::make_optional<DirContext>(dirContext_.back());
}
void PushContext(const parser::CharBlock &source, T dir, Scope &scope) {
dirContext_.emplace_back(source, dir, scope);
if constexpr (std::is_same_v<T, llvm::acc::Directive>) {
dirContext_.emplace_back(source, dir, scope);
if (std::size_t size{dirContext_.size()}; size > 1) {
std::size_t lastIndex{size - 1};
dirContext_[lastIndex].defaultDSA =
dirContext_[lastIndex - 1].defaultDSA;
}
} else {
dirContext_.emplace_back(source, dir, scope);
}
}
void PushContext(const parser::CharBlock &source, T dir) {
dirContext_.emplace_back(source, dir, context_.FindScope(source));
PushContext(source, dir, context_.FindScope(source));
}
void PopContext() { dirContext_.pop_back(); }
void SetContextDirectiveSource(parser::CharBlock &dir) {
Expand All @@ -100,9 +115,21 @@ template <typename T> class DirectiveAttributeVisitor {
AddToContextObjectWithDSA(symbol, flag, GetContext());
}
bool IsObjectWithDSA(const Symbol &symbol) {
auto it{GetContext().objectWithDSA.find(&symbol)};
return it != GetContext().objectWithDSA.end();
return GetContext().FindSymbolWithDSA(symbol).has_value();
}
bool IsObjectWithVisibleDSA(const Symbol &symbol) {
for (std::size_t i{dirContext_.size()}; i != 0; i--) {
if (dirContext_[i - 1].FindSymbolWithDSA(symbol).has_value()) {
return true;
}
}
return false;
}

bool WithinConstruct() {
return !dirContext_.empty() && GetContext().withinConstruct;
}

void SetContextAssociatedLoopLevel(std::int64_t level) {
GetContext().associatedLoopLevel = level;
}
Expand Down Expand Up @@ -1573,10 +1600,10 @@ void AccAttributeVisitor::Post(const parser::AccDefaultClause &x) {
// and adjust the symbol for each Name if necessary
void AccAttributeVisitor::Post(const parser::Name &name) {
auto *symbol{name.symbol};
if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
if (symbol && WithinConstruct()) {
symbol = &symbol->GetUltimate();
if (!symbol->owner().IsDerivedType() && !symbol->has<ProcEntityDetails>() &&
!symbol->has<SubprogramDetails>() && !IsObjectWithDSA(*symbol)) {
!symbol->has<SubprogramDetails>() && !IsObjectWithVisibleDSA(*symbol)) {
if (Symbol * found{currScope().FindSymbol(name.source)}) {
if (symbol != found) {
name.symbol = found; // adjust the symbol within region
Expand Down Expand Up @@ -1959,7 +1986,7 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
// till OpenMP-5.0 standard.
// In above both cases we skip the privatization of iteration variables.
bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
if (!dirContext_.empty() && GetContext().withinConstruct) {
if (WithinConstruct()) {
llvm::SmallVector<const parser::Name *> ivs;
if (x.IsDoNormal()) {
const parser::Name *iv{GetLoopIndex(x)};
Expand Down Expand Up @@ -2685,7 +2712,7 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
void OmpAttributeVisitor::Post(const parser::Name &name) {
auto *symbol{name.symbol};

if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
if (symbol && WithinConstruct()) {
if (IsPrivatizable(symbol) && !IsObjectWithDSA(*symbol)) {
// TODO: create a separate function to go through the rules for
// predetermined, explicitly determined, and implicitly
Expand Down
22 changes: 22 additions & 0 deletions flang/test/Semantics/OpenACC/acc-parallel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,25 @@ program openacc_parallel_validity
!$acc end parallel

end program openacc_parallel_validity

subroutine acc_parallel_default_none
integer :: i, l
real :: a(10,10)
l = 10
!$acc parallel default(none)
!$acc loop
!ERROR: The DEFAULT(NONE) clause requires that 'l' must be listed in a data-mapping clause
do i = 1, l
!ERROR: The DEFAULT(NONE) clause requires that 'a' must be listed in a data-mapping clause
a(1,i) = 1
end do
!$acc end parallel

!$acc data copy(a)
!$acc parallel loop firstprivate(l) default(none)
do i = 1, l
a(1,i) = 1
end do
!$acc end parallel
!$acc end data
end subroutine acc_parallel_default_none