@@ -2735,51 +2735,54 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
2735
2735
2736
2736
if (GetContext ().directive == llvm::omp::Directive::OMPD_task) {
2737
2737
if (auto *detachClause{FindClause (llvm::omp::Clause::OMPC_detach)}) {
2738
- // OpenMP 5.0: Task construct restrictions
2739
- CheckNotAllowedIfClause (
2740
- llvm::omp::Clause::OMPC_detach, {llvm::omp::Clause::OMPC_mergeable});
2741
-
2742
- // OpenMP 5.2: Task construct restrictions
2743
- if (FindClause (llvm::omp::Clause::OMPC_final)) {
2744
- context_.Say (GetContext ().clauseSource ,
2745
- " If a DETACH clause appears on a directive, then the encountering task must not be a FINAL task" _err_en_US);
2746
- }
2738
+ unsigned version{context_.langOptions ().OpenMPVersion };
2739
+ if (version == 50 || version == 51 ) {
2740
+ // OpenMP 5.0: 2.10.1 Task construct restrictions
2741
+ CheckNotAllowedIfClause (
2742
+ llvm::omp::Clause::OMPC_detach, {llvm::omp::Clause::OMPC_mergeable});
2743
+ } else if (version >= 52 ) {
2744
+ // OpenMP 5.2: 12.5.2 Detach construct restrictions
2745
+ if (FindClause (llvm::omp::Clause::OMPC_final)) {
2746
+ context_.Say (GetContext ().clauseSource ,
2747
+ " If a DETACH clause appears on a directive, then the encountering task must not be a FINAL task" _err_en_US);
2748
+ }
2747
2749
2748
- const auto &detach{
2749
- std::get<parser::OmpClause::Detach>(detachClause->u )};
2750
- if (const auto *name{parser::Unwrap<parser::Name>(detach.v .v )}) {
2751
- if (name->symbol ) {
2752
- Symbol *eventHandleSym{name->symbol ->GetUltimate ()};
2753
- auto checkVarAppearsInDataEnvClause = [&](const parser::OmpObjectList
2754
- &objs,
2755
- std::string clause) {
2756
- for (const auto &obj : objs.v ) {
2757
- if (const parser::Name *objName{
2758
- parser::Unwrap<parser::Name>(obj)}) {
2759
- if (objName->symbol ->GetUltimate () == eventHandleSym) {
2760
- context_.Say (GetContext ().clauseSource ,
2761
- " A variable: `%s` that appears in a DETACH clause cannot appear on %s clause on the same construct" _err_en_US,
2762
- objName->source , clause);
2750
+ const auto &detach{
2751
+ std::get<parser::OmpClause::Detach>(detachClause->u )};
2752
+ if (const auto *name{parser::Unwrap<parser::Name>(detach.v .v )}) {
2753
+ if (name->symbol ) {
2754
+ Symbol *eventHandleSym{name->symbol };
2755
+ auto checkVarAppearsInDataEnvClause = [&](const parser::OmpObjectList
2756
+ &objs,
2757
+ std::string clause) {
2758
+ for (const auto &obj : objs.v ) {
2759
+ if (const parser::Name *objName{
2760
+ parser::Unwrap<parser::Name>(obj)}) {
2761
+ if (&objName->symbol ->GetUltimate () == eventHandleSym) {
2762
+ context_.Say (GetContext ().clauseSource ,
2763
+ " A variable: `%s` that appears in a DETACH clause cannot appear on %s clause on the same construct" _err_en_US,
2764
+ objName->source , clause);
2765
+ }
2763
2766
}
2764
2767
}
2768
+ };
2769
+ if (auto *dataEnvClause{
2770
+ FindClause (llvm::omp::Clause::OMPC_private)}) {
2771
+ const auto &pClause{
2772
+ std::get<parser::OmpClause::Private>(dataEnvClause->u )};
2773
+ checkVarAppearsInDataEnvClause (pClause.v , " PRIVATE" );
2774
+ } else if (auto *dataEnvClause{
2775
+ FindClause (llvm::omp::Clause::OMPC_firstprivate)}) {
2776
+ const auto &fpClause{
2777
+ std::get<parser::OmpClause::Firstprivate>(dataEnvClause->u )};
2778
+ checkVarAppearsInDataEnvClause (fpClause.v , " FIRSTPRIVATE" );
2779
+ } else if (auto *dataEnvClause{
2780
+ FindClause (llvm::omp::Clause::OMPC_in_reduction)}) {
2781
+ const auto &irClause{
2782
+ std::get<parser::OmpClause::InReduction>(dataEnvClause->u )};
2783
+ checkVarAppearsInDataEnvClause (
2784
+ std::get<parser::OmpObjectList>(irClause.v .t ), " IN_REDUCTION" );
2765
2785
}
2766
- };
2767
- if (auto *dataEnvClause{
2768
- FindClause (llvm::omp::Clause::OMPC_private)}) {
2769
- const auto &pClause{
2770
- std::get<parser::OmpClause::Private>(dataEnvClause->u )};
2771
- checkVarAppearsInDataEnvClause (pClause.v , " PRIVATE" );
2772
- } else if (auto *dataEnvClause{
2773
- FindClause (llvm::omp::Clause::OMPC_firstprivate)}) {
2774
- const auto &fpClause{
2775
- std::get<parser::OmpClause::Firstprivate>(dataEnvClause->u )};
2776
- checkVarAppearsInDataEnvClause (fpClause.v , " FIRSTPRIVATE" );
2777
- } else if (auto *dataEnvClause{
2778
- FindClause (llvm::omp::Clause::OMPC_in_reduction)}) {
2779
- const auto &irClause{
2780
- std::get<parser::OmpClause::InReduction>(dataEnvClause->u )};
2781
- checkVarAppearsInDataEnvClause (
2782
- std::get<parser::OmpObjectList>(irClause.v .t ), " IN_REDUCTION" );
2783
2786
}
2784
2787
}
2785
2788
}
@@ -3804,23 +3807,25 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
3804
3807
}
3805
3808
3806
3809
void OmpStructureChecker::Enter (const parser::OmpClause::Detach &x) {
3807
- // OpenMP 5.0: Task construct restrictions
3808
3810
CheckAllowedClause (llvm::omp::Clause::OMPC_detach);
3811
+ unsigned version{context_.langOptions ().OpenMPVersion };
3812
+ // OpenMP 5.2: 12.5.2 Detach clause restrictions
3813
+ if (version >= 52 ) {
3814
+ CheckIsVarPartOfAnotherVar (GetContext ().clauseSource , x.v .v , " DETACH" );
3815
+ }
3809
3816
3810
- // OpenMP 5.2: Detach clause restrictions
3811
- CheckIsVarPartOfAnotherVar (GetContext ().clauseSource , x.v .v , " DETACH" );
3812
3817
if (const auto *name{parser::Unwrap<parser::Name>(x.v .v )}) {
3813
3818
if (name->symbol ) {
3814
- if (IsPointer (*name->symbol )) {
3819
+ if (version >= 52 && IsPointer (*name->symbol )) {
3815
3820
context_.Say (GetContext ().clauseSource ,
3816
3821
" The event-handle: `%s` must not have the POINTER attribute" _err_en_US,
3817
3822
name->ToString ());
3818
3823
}
3819
- }
3820
- if (!name-> symbol -> GetType ()-> IsNumeric (TypeCategory::Integer)) {
3821
- context_. Say ( GetContext (). clauseSource ,
3822
- " The event-handle: `%s` must be of type integer(kind=omp_event_handle_kind) " _err_en_US,
3823
- name-> ToString ());
3824
+ if (!name-> symbol -> GetType ()-> IsNumeric (TypeCategory::Integer)) {
3825
+ context_. Say ( GetContext (). clauseSource ,
3826
+ " The event-handle: `%s` must be of type integer(kind=omp_event_handle_kind) " _err_en_US ,
3827
+ name-> ToString ());
3828
+ }
3824
3829
}
3825
3830
}
3826
3831
}
0 commit comments