From: Samuel Antao Date: Tue, 19 Jan 2016 20:40:49 +0000 (+0000) Subject: [OpenMP] Detect implicit map type to report unspecified map type for target enter... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a064ffc5ba97a5dc6daec023ed0944ffb37d42e4;p=clang [OpenMP] Detect implicit map type to report unspecified map type for target enter/exit data directives. Support for the following OpenMP 4.5 restriction on 'target enter data' and 'target exit data': - A map-type must be specified in all map clauses. I have to save 'IsMapTypeImplicit' when parsing a map clause to support this constraint and for more informative error messages. This helps me support the following case: #pragma omp target enter data map(r) // expected-error {{map type must be specified for '#pragma omp target enter data'}} and distinguish it from: #pragma omp target enter data map(tofrom: r) // expected-error {{map type 'tofrom' is not allowed for '#pragma omp target enter data'}} Patch by Arpith Jacob. Thanks! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258179 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index 1275b7f0bb..f7bfd73721 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -2741,6 +2741,8 @@ class OMPMapClause final : public OMPVarListClause, OpenMPMapClauseKind MapTypeModifier; /// \brief Map type for the 'map' clause. OpenMPMapClauseKind MapType; + /// \brief Is this an implicit map type or not. + bool MapTypeIsImplicit; /// \brief Location of the map type. SourceLocation MapLoc; /// \brief Colon location. @@ -2771,17 +2773,21 @@ class OMPMapClause final : public OMPVarListClause, /// /// \param MapTypeModifier Map type modifier. /// \param MapType Map type. + /// \param MapTypeIsImplicit Map type is inferred implicitly. /// \param MapLoc Location of the map type. /// \param StartLoc Starting location of the clause. /// \param EndLoc Ending location of the clause. /// \param N Number of the variables in the clause. /// explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier, - OpenMPMapClauseKind MapType, SourceLocation MapLoc, - SourceLocation StartLoc, SourceLocation LParenLoc, - SourceLocation EndLoc, unsigned N) - : OMPVarListClause(OMPC_map, StartLoc, LParenLoc, EndLoc, N), - MapTypeModifier(MapTypeModifier), MapType(MapType), MapLoc(MapLoc) {} + OpenMPMapClauseKind MapType, bool MapTypeIsImplicit, + SourceLocation MapLoc, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc, + unsigned N) + : OMPVarListClause(OMPC_map, StartLoc, LParenLoc, EndLoc, + N), + MapTypeModifier(MapTypeModifier), MapType(MapType), + MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {} /// \brief Build an empty clause. /// @@ -2790,7 +2796,8 @@ class OMPMapClause final : public OMPVarListClause, explicit OMPMapClause(unsigned N) : OMPVarListClause(OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(), N), - MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown), MapLoc() {} + MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown), + MapTypeIsImplicit(false), MapLoc() {} public: /// \brief Creates clause with a list of variables \a VL. @@ -2801,13 +2808,15 @@ public: /// \param VL List of references to the variables. /// \param TypeModifier Map type modifier. /// \param Type Map type. + /// \param TypeIsImplicit Map type is inferred implicitly. /// \param TypeLoc Location of the map type. /// static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc, - SourceLocation LParenLoc, - SourceLocation EndLoc, ArrayRef VL, + SourceLocation LParenLoc, SourceLocation EndLoc, + ArrayRef VL, OpenMPMapClauseKind TypeModifier, - OpenMPMapClauseKind Type, SourceLocation TypeLoc); + OpenMPMapClauseKind Type, bool TypeIsImplicit, + SourceLocation TypeLoc); /// \brief Creates an empty clause with the place for \a N variables. /// /// \param C AST context. @@ -2818,6 +2827,13 @@ public: /// \brief Fetches mapping kind for the clause. OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; } + /// \brief Is this an implicit map type? + /// We have to capture 'IsMapTypeImplicit' from the parser for more + /// informative error messages. It helps distinguish map(r) from + /// map(tofrom: r), which is important to print more helpful error + /// messages for some target directives. + bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; } + /// \brief Fetches the map type modifier for the clause. OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY { return MapTypeModifier; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 8eaa98803c..55b393f656 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -8121,7 +8121,8 @@ public: CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, - OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc); + OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, + SourceLocation DepLinMapLoc); /// \brief Called on well-formed 'private' clause. OMPClause *ActOnOpenMPPrivateClause(ArrayRef VarList, SourceLocation StartLoc, @@ -8188,10 +8189,12 @@ public: SourceLocation LParenLoc, SourceLocation EndLoc); /// \brief Called on well-formed 'map' clause. - OMPClause *ActOnOpenMPMapClause( - OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, - SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef VarList, - SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); + OMPClause * + ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, + OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, + SourceLocation MapLoc, SourceLocation ColonLoc, + ArrayRef VarList, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc); /// \brief Called on well-formed 'num_teams' clause. OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/lib/AST/OpenMPClause.cpp b/lib/AST/OpenMPClause.cpp index 1ef43f7694..1d1da53732 100644 --- a/lib/AST/OpenMPClause.cpp +++ b/lib/AST/OpenMPClause.cpp @@ -400,10 +400,12 @@ OMPMapClause *OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef VL, OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type, + bool TypeIsImplicit, SourceLocation TypeLoc) { void *Mem = C.Allocate(totalSizeToAlloc(VL.size())); - OMPMapClause *Clause = new (Mem) OMPMapClause( - TypeModifier, Type, TypeLoc, StartLoc, LParenLoc, EndLoc, VL.size()); + OMPMapClause *Clause = + new (Mem) OMPMapClause(TypeModifier, Type, TypeIsImplicit, TypeLoc, + StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setMapTypeModifier(TypeModifier); Clause->setMapType(Type); diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 94d90c0e21..a2e887f7cf 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -898,6 +898,7 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val; OpenMPMapClauseKind MapType = OMPC_MAP_unknown; OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown; + bool MapTypeIsImplicit = false; bool MapTypeModifierSpecified = false; bool UnexpectedId = false; SourceLocation DepLinMapLoc; @@ -948,7 +949,8 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, Kind, llvm::None, /*TailExpr=*/nullptr, Loc, LOpen, /*ColonLoc=*/SourceLocation(), Tok.getLocation(), ReductionIdScopeSpec, DeclarationNameInfo(), DepKind, - LinearModifier, MapTypeModifier, MapType, DepLinMapLoc); + LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, + DepLinMapLoc); } } if (Tok.is(tok::colon)) { @@ -1012,9 +1014,11 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, ConsumeToken(); } else { MapType = OMPC_MAP_tofrom; + MapTypeIsImplicit = true; } } else { MapType = OMPC_MAP_tofrom; + MapTypeIsImplicit = true; } } else { UnexpectedId = true; @@ -1095,6 +1099,7 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, ReductionIdScopeSpec, ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) : DeclarationNameInfo(), - DepKind, LinearModifier, MapTypeModifier, MapType, DepLinMapLoc); + DepKind, LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, + DepLinMapLoc); } diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 1b51553638..3817704a1a 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -6513,8 +6513,9 @@ OMPClause *Sema::ActOnOpenMPVarListClause( SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, - OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, - OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { + OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, + OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, + SourceLocation DepLinMapLoc) { OMPClause *Res = nullptr; switch (Kind) { case OMPC_private: @@ -6555,8 +6556,9 @@ OMPClause *Sema::ActOnOpenMPVarListClause( StartLoc, LParenLoc, EndLoc); break; case OMPC_map: - Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, - VarList, StartLoc, LParenLoc, EndLoc); + Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, + DepLinMapLoc, ColonLoc, VarList, StartLoc, + LParenLoc, EndLoc); break; case OMPC_if: case OMPC_final: @@ -8474,10 +8476,12 @@ static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, return true; } -OMPClause *Sema::ActOnOpenMPMapClause( - OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, - SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef VarList, - SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { +OMPClause * +Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, + OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, + SourceLocation MapLoc, SourceLocation ColonLoc, + ArrayRef VarList, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc) { SmallVector Vars; for (auto &RE : VarList) { @@ -8592,9 +8596,8 @@ OMPClause *Sema::ActOnOpenMPMapClause( if (DKind == OMPD_target_enter_data && !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) - << - // TODO: Need to determine if map type is implicitly determined - 0 << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) + << (IsMapTypeImplicit ? 1 : 0) + << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) << getOpenMPDirectiveName(DKind); // Proceed to add the variable in a map clause anyway, to prevent // further spurious messages @@ -8609,9 +8612,8 @@ OMPClause *Sema::ActOnOpenMPMapClause( !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || MapType == OMPC_MAP_delete)) { Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) - << - // TODO: Need to determine if map type is implicitly determined - 0 << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) + << (IsMapTypeImplicit ? 1 : 0) + << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) << getOpenMPDirectiveName(DKind); // Proceed to add the variable in a map clause anyway, to prevent // further spurious messages @@ -8625,7 +8627,8 @@ OMPClause *Sema::ActOnOpenMPMapClause( return nullptr; return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, - MapTypeModifier, MapType, MapLoc); + MapTypeModifier, MapType, IsMapTypeImplicit, + MapLoc); } OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 3b43573195..11793c6ebc 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1658,14 +1658,15 @@ public: /// /// By default, performs semantic analysis to build the new OpenMP clause. /// Subclasses may override this routine to provide different behavior. - OMPClause *RebuildOMPMapClause( - OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, - SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef VarList, - SourceLocation StartLoc, SourceLocation LParenLoc, - SourceLocation EndLoc) { - return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, MapLoc, - ColonLoc, VarList,StartLoc, - LParenLoc, EndLoc); + OMPClause * + RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier, + OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, + SourceLocation MapLoc, SourceLocation ColonLoc, + ArrayRef VarList, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc) { + return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, + IsMapTypeImplicit, MapLoc, ColonLoc, + VarList, StartLoc, LParenLoc, EndLoc); } /// \brief Build a new OpenMP 'num_teams' clause. @@ -7860,9 +7861,9 @@ OMPClause *TreeTransform::TransformOMPMapClause(OMPMapClause *C) { Vars.push_back(EVar.get()); } return getDerived().RebuildOMPMapClause( - C->getMapTypeModifier(), C->getMapType(), C->getMapLoc(), - C->getColonLoc(), Vars, C->getLocStart(), C->getLParenLoc(), - C->getLocEnd()); + C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(), + C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(), + C->getLParenLoc(), C->getLocEnd()); } template diff --git a/test/OpenMP/target_enter_data_map_messages.c b/test/OpenMP/target_enter_data_map_messages.c index fcb27a0b79..e927ea61ad 100644 --- a/test/OpenMP/target_enter_data_map_messages.c +++ b/test/OpenMP/target_enter_data_map_messages.c @@ -5,6 +5,7 @@ int main(int argc, char **argv) { int r; #pragma omp target enter data // expected-error {{expected at least one map clause for '#pragma omp target enter data'}} + #pragma omp target enter data map(r) // expected-error {{map type must be specified for '#pragma omp target enter data'}} #pragma omp target enter data map(tofrom: r) // expected-error {{map type 'tofrom' is not allowed for '#pragma omp target enter data'}} #pragma omp target enter data map(always, to: r) diff --git a/test/OpenMP/target_exit_data_map_messages.c b/test/OpenMP/target_exit_data_map_messages.c index ec4f576aeb..26178e19e6 100644 --- a/test/OpenMP/target_exit_data_map_messages.c +++ b/test/OpenMP/target_exit_data_map_messages.c @@ -5,6 +5,7 @@ int main(int argc, char **argv) { int r; #pragma omp target exit data // expected-error {{expected at least one map clause for '#pragma omp target exit data'}} + #pragma omp target exit data map(r) // expected-error {{map type must be specified for '#pragma omp target exit data'}} #pragma omp target exit data map(tofrom: r) // expected-error {{map type 'tofrom' is not allowed for '#pragma omp target exit data'}} #pragma omp target exit data map(always, from: r)