Skip to content

Commit 63b6d7d

Browse files
committed
Simplify checks for predefined allocator
1 parent fc9b35d commit 63b6d7d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,13 +1717,16 @@ void OmpStructureChecker::CheckAllocateDirective(parser::CharBlock source,
17171717
SymbolSourceMap symbols;
17181718
GetSymbolsInObjectList(objects, symbols);
17191719

1720-
auto hasPredefinedAllocator{[&](const parser::OmpClause *c) {
1721-
if (!c) {
1722-
return std::make_optional(false);
1720+
auto maybeHasPredefinedAllocator{[&](const parser::OmpClause *calloc) {
1721+
// Return "true" if the ALLOCATOR clause was provided with an argument
1722+
// that is either a prefdefined allocator, or a run-time value.
1723+
// Otherwise return "false".
1724+
if (!calloc) {
1725+
return false;
17231726
}
1724-
auto *allocator{std::get_if<parser::OmpClause::Allocator>(&c->u)};
1725-
if (auto val{ToInt64(GetEvaluateExpr(allocator->v))}) {
1726-
// Predefined allocators:
1727+
auto *allocator{std::get_if<parser::OmpClause::Allocator>(&calloc->u)};
1728+
if (auto val{ToInt64(GetEvaluateExpr(DEREF(allocator).v))}) {
1729+
// Predefined allocators (defined in OpenMP 6.0 20.8.1):
17271730
// omp_null_allocator = 0,
17281731
// omp_default_mem_alloc = 1,
17291732
// omp_large_cap_mem_alloc = 2,
@@ -1733,9 +1736,9 @@ void OmpStructureChecker::CheckAllocateDirective(parser::CharBlock source,
17331736
// omp_cgroup_mem_alloc = 6,
17341737
// omp_pteam_mem_alloc = 7,
17351738
// omp_thread_mem_alloc = 8
1736-
return std::make_optional(*val >= 0 && *val <= 8);
1739+
return *val >= 0 && *val <= 8;
17371740
}
1738-
return std::optional<bool>{};
1741+
return true;
17391742
}};
17401743

17411744
const auto *allocator{FindClause(llvm::omp::Clause::OMPC_allocator)};
@@ -1748,7 +1751,7 @@ void OmpStructureChecker::CheckAllocateDirective(parser::CharBlock source,
17481751
}
17491752
}
17501753

1751-
bool isPredefined{hasPredefinedAllocator(allocator).value_or(false)};
1754+
auto maybePredefined{maybeHasPredefinedAllocator(allocator)};
17521755

17531756
for (auto &[symbol, source] : symbols) {
17541757
if (!inExecutableAllocate_) {
@@ -1769,9 +1772,9 @@ void OmpStructureChecker::CheckAllocateDirective(parser::CharBlock source,
17691772
if (!allocator) {
17701773
context_.Say(source,
17711774
"If a list item is a named common block or has SAVE attribute, an ALLOCATOR clause must be present with a predefined allocator"_err_en_US);
1772-
} else if (!isPredefined) {
1775+
} else if (!maybePredefined) {
17731776
context_.Say(source,
1774-
"If a list item is a named common block or has SAVE attribute, only a predefined allocator may be used on the ALLOCATOR clause"_warn_en_US);
1777+
"If a list item is a named common block or has SAVE attribute, only a predefined allocator may be used on the ALLOCATOR clause"_err_en_US);
17751778
}
17761779
}
17771780
if (FindCommonBlockContaining(*symbol)) {

flang/test/Semantics/OpenMP/allocate08.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ subroutine allocate(custom_allocator)
3535

3636
!$omp allocate(w) allocator(custom_allocator)
3737

38-
!ERROR: If a list item is a named common block or has SAVE attribute, only a predefined allocator may be used on the ALLOCATOR clause
3938
!$omp allocate(x) allocator(custom_allocator)
4039
!ERROR: A variable that is part of a common block may not be specified as a list item in an ALLOCATE directive, except implicitly via the named common block
4140
!$omp allocate(y) allocator(custom_allocator)

0 commit comments

Comments
 (0)