-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Flang] [OpenMP] Add semantic checks for detach clause in task #119172
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
Changes from 9 commits
6e491cc
fa2b051
569712f
42cc3e7
a3c6a45
019a24c
0348571
2c09c87
e94e30d
94a7504
6fc96f7
59075c1
965df85
d13d267
573580e
5d9be32
47fbdc4
596d326
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2961,6 +2961,63 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) { | |||||
// clause | ||||||
CheckMultListItems(); | ||||||
|
||||||
if (GetContext().directive == llvm::omp::Directive::OMPD_task) { | ||||||
if (auto *detachClause{FindClause(llvm::omp::Clause::OMPC_detach)}) { | ||||||
unsigned version{context_.langOptions().OpenMPVersion}; | ||||||
if (version == 50 || version == 51) { | ||||||
// OpenMP 5.0: 2.10.1 Task construct restrictions | ||||||
CheckNotAllowedIfClause(llvm::omp::Clause::OMPC_detach, | ||||||
{llvm::omp::Clause::OMPC_mergeable}); | ||||||
} else if (version >= 52) { | ||||||
// OpenMP 5.2: 12.5.2 Detach construct restrictions | ||||||
if (FindClause(llvm::omp::Clause::OMPC_final)) { | ||||||
context_.Say(GetContext().clauseSource, | ||||||
"If a DETACH clause appears on a directive, then the encountering task must not be a FINAL task"_err_en_US); | ||||||
} | ||||||
|
||||||
const auto &detach{ | ||||||
std::get<parser::OmpClause::Detach>(detachClause->u)}; | ||||||
if (const auto *name{parser::Unwrap<parser::Name>(detach.v.v)}) { | ||||||
if (name->symbol) { | ||||||
Symbol *eventHandleSym{name->symbol}; | ||||||
auto checkVarAppearsInDataEnvClause = [&](const parser:: | ||||||
OmpObjectList &objs, | ||||||
std::string clause) { | ||||||
for (const auto &obj : objs.v) { | ||||||
if (const parser::Name * | ||||||
objName{parser::Unwrap<parser::Name>(obj)}) { | ||||||
if (&objName->symbol->GetUltimate() == eventHandleSym) { | ||||||
context_.Say(GetContext().clauseSource, | ||||||
"A variable: `%s` that appears in a DETACH clause cannot appear on %s clause on the same construct"_err_en_US, | ||||||
objName->source, clause); | ||||||
} | ||||||
} | ||||||
} | ||||||
}; | ||||||
if (auto *dataEnvClause{ | ||||||
FindClause(llvm::omp::Clause::OMPC_private)}) { | ||||||
const auto &pClause{ | ||||||
std::get<parser::OmpClause::Private>(dataEnvClause->u)}; | ||||||
checkVarAppearsInDataEnvClause(pClause.v, "PRIVATE"); | ||||||
} else if (auto *dataEnvClause{ | ||||||
FindClause(llvm::omp::Clause::OMPC_firstprivate)}) { | ||||||
const auto &fpClause{ | ||||||
std::get<parser::OmpClause::Firstprivate>(dataEnvClause->u)}; | ||||||
checkVarAppearsInDataEnvClause(fpClause.v, "FIRSTPRIVATE"); | ||||||
} else if (auto *dataEnvClause{ | ||||||
FindClause(llvm::omp::Clause::OMPC_in_reduction)}) { | ||||||
const auto &irClause{ | ||||||
std::get<parser::OmpClause::InReduction>(dataEnvClause->u)}; | ||||||
checkVarAppearsInDataEnvClause( | ||||||
std::get<parser::OmpObjectList>(irClause.v.t), | ||||||
"IN_REDUCTION"); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about SHARED? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I don't know how I missed this. |
||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
auto testThreadprivateVarErr = [&](Symbol sym, parser::Name name, | ||||||
llvmOmpClause clauseTy) { | ||||||
if (sym.test(Symbol::Flag::OmpThreadprivate)) | ||||||
|
@@ -3043,7 +3100,6 @@ CHECK_SIMPLE_CLAUSE(Capture, OMPC_capture) | |||||
CHECK_SIMPLE_CLAUSE(Contains, OMPC_contains) | ||||||
CHECK_SIMPLE_CLAUSE(Default, OMPC_default) | ||||||
CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj) | ||||||
CHECK_SIMPLE_CLAUSE(Detach, OMPC_detach) | ||||||
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type) | ||||||
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule) | ||||||
CHECK_SIMPLE_CLAUSE(Exclusive, OMPC_exclusive) | ||||||
|
@@ -3627,40 +3683,45 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar( | |||||
const parser::CharBlock &source, const parser::OmpObjectList &objList, | ||||||
llvm::StringRef clause) { | ||||||
for (const auto &ompObject : objList.v) { | ||||||
common::visit( | ||||||
common::visitors{ | ||||||
[&](const parser::Designator &designator) { | ||||||
if (const auto *dataRef{ | ||||||
std::get_if<parser::DataRef>(&designator.u)}) { | ||||||
if (IsDataRefTypeParamInquiry(dataRef)) { | ||||||
CheckIsVarPartOfAnotherVar(source, ompObject, clause); | ||||||
} | ||||||
} | ||||||
|
||||||
void OmpStructureChecker::CheckIsVarPartOfAnotherVar( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion, feel free to ignore. I think this would be clearer
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
const parser::CharBlock &source, const parser::OmpObject &ompObject, | ||||||
llvm::StringRef clause) { | ||||||
common::visit( | ||||||
common::visitors{ | ||||||
[&](const parser::Designator &designator) { | ||||||
if (const auto *dataRef{ | ||||||
std::get_if<parser::DataRef>(&designator.u)}) { | ||||||
if (IsDataRefTypeParamInquiry(dataRef)) { | ||||||
context_.Say(source, | ||||||
"A type parameter inquiry cannot appear on the %s " | ||||||
"directive"_err_en_US, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make message strings be in a single line (here and in other places you've changed). This is to make it easier to find them in the source based on the compiler output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
ContextDirectiveAsFortran()); | ||||||
} else if (parser::Unwrap<parser::StructureComponent>( | ||||||
ompObject) || | ||||||
parser::Unwrap<parser::ArrayElement>(ompObject)) { | ||||||
if (llvm::omp::nonPartialVarSet.test(GetContext().directive)) { | ||||||
context_.Say(source, | ||||||
"A type parameter inquiry cannot appear on the %s " | ||||||
"A variable that is part of another variable (as an " | ||||||
"array or structure element) cannot appear on the %s " | ||||||
"directive"_err_en_US, | ||||||
ContextDirectiveAsFortran()); | ||||||
} else if (parser::Unwrap<parser::StructureComponent>( | ||||||
ompObject) || | ||||||
parser::Unwrap<parser::ArrayElement>(ompObject)) { | ||||||
if (llvm::omp::nonPartialVarSet.test( | ||||||
GetContext().directive)) { | ||||||
context_.Say(source, | ||||||
"A variable that is part of another variable (as an " | ||||||
"array or structure element) cannot appear on the %s " | ||||||
"directive"_err_en_US, | ||||||
ContextDirectiveAsFortran()); | ||||||
} else { | ||||||
context_.Say(source, | ||||||
"A variable that is part of another variable (as an " | ||||||
"array or structure element) cannot appear in a " | ||||||
"%s clause"_err_en_US, | ||||||
clause.data()); | ||||||
} | ||||||
} else { | ||||||
context_.Say(source, | ||||||
"A variable that is part of another variable (as an " | ||||||
"array or structure element) cannot appear in a " | ||||||
"%s clause"_err_en_US, | ||||||
clause.data()); | ||||||
} | ||||||
} | ||||||
}, | ||||||
[&](const parser::Name &name) {}, | ||||||
}, | ||||||
ompObject.u); | ||||||
} | ||||||
} | ||||||
}, | ||||||
[&](const parser::Name &name) {}, | ||||||
}, | ||||||
ompObject.u); | ||||||
} | ||||||
|
||||||
void OmpStructureChecker::Enter(const parser::OmpClause::Firstprivate &x) { | ||||||
|
@@ -3989,6 +4050,31 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) { | |||||
} | ||||||
} | ||||||
|
||||||
void OmpStructureChecker::Enter(const parser::OmpClause::Detach &x) { | ||||||
// OpenMP 5.0: 2.10.1 Task construct restrictions | ||||||
CheckAllowedClause(llvm::omp::Clause::OMPC_detach); | ||||||
// OpenMP 5.2: 12.5.2 Detach clause restrictions | ||||||
unsigned version{context_.langOptions().OpenMPVersion}; | ||||||
if (version >= 52) { | ||||||
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v.v, "DETACH"); | ||||||
} | ||||||
|
||||||
if (const auto *name{parser::Unwrap<parser::Name>(x.v.v)}) { | ||||||
if (name->symbol) { | ||||||
if (version >= 52 && IsPointer(*name->symbol)) { | ||||||
context_.Say(GetContext().clauseSource, | ||||||
"The event-handle: `%s` must not have the POINTER attribute"_err_en_US, | ||||||
name->ToString()); | ||||||
} | ||||||
if (!name->symbol->GetType()->IsNumeric(TypeCategory::Integer)) { | ||||||
context_.Say(GetContext().clauseSource, | ||||||
"The event-handle: `%s` must be of type integer(kind=omp_event_handle_kind)"_err_en_US, | ||||||
name->ToString()); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
void OmpStructureChecker::CheckAllowedMapTypes( | ||||||
const parser::OmpMapType::Value &type, | ||||||
const std::list<parser::OmpMapType::Value> &allowedMapTypeList) { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
! REQUIRES: openmp_runtime | ||
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=52 | ||
|
||
! OpenMP Version 5.2: 12.5.2 | ||
! Various checks for DETACH Clause | ||
|
||
program detach01 | ||
use omp_lib, only: omp_event_handle_kind | ||
implicit none | ||
real :: e, x | ||
integer(omp_event_handle_kind) :: event_01, event_02(2) | ||
integer(omp_event_handle_kind), pointer :: event_03 | ||
|
||
type :: t | ||
integer(omp_event_handle_kind) :: event | ||
end type | ||
type(t) :: t_01 | ||
|
||
!ERROR: The event-handle: `e` must be of type integer(kind=omp_event_handle_kind) | ||
!$omp task detach(e) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: If a DETACH clause appears on a directive, then the encountering task must not be a FINAL task | ||
!$omp task detach(event_01) final(.false.) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: A variable: `event_01` that appears in a DETACH clause cannot appear on PRIVATE clause on the same construct | ||
!$omp task detach(event_01) private(event_01) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: A variable: `event_01` that appears in a DETACH clause cannot appear on IN_REDUCTION clause on the same construct | ||
!$omp task detach(event_01) in_reduction(+:event_01) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a DETACH clause | ||
!$omp task detach(event_02(1)) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a DETACH clause | ||
!$omp task detach(t_01%event) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: The event-handle: `event_03` must not have the POINTER attribute | ||
!$omp task detach(event_03) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: At most one DETACH clause can appear on the TASK directive | ||
!$omp task detach(event_01) detach(event_02) | ||
x = x + 1 | ||
!$omp end task | ||
end program |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
! REQUIRES: openmp_runtime | ||
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=50 | ||
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=51 | ||
|
||
! OpenMP Version 5.0: 2.10.1 | ||
! Various checks for DETACH Clause | ||
|
||
program detach02 | ||
use omp_lib, only: omp_event_handle_kind | ||
integer(omp_event_handle_kind) :: event_01, event_02 | ||
|
||
!ERROR: At most one DETACH clause can appear on the TASK directive | ||
!$omp task detach(event_01) detach(event_02) | ||
x = x + 1 | ||
!$omp end task | ||
|
||
!ERROR: Clause MERGEABLE is not allowed if clause DETACH appears on the TASK directive | ||
!$omp task detach(event_01) mergeable | ||
x = x + 1 | ||
!$omp end task | ||
end program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All parser::Name's should have non-null symbols by now (it's an internal compiler error if they don't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done