Index: include/clang/AST/OpenMPClause.h =================================================================== --- include/clang/AST/OpenMPClause.h +++ include/clang/AST/OpenMPClause.h @@ -2741,6 +2741,8 @@ 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,20 @@ /// /// \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) + 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), MapLoc(MapLoc) {} + MapTypeModifier(MapTypeModifier), MapType(MapType), + MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {} /// \brief Build an empty clause. /// @@ -2790,7 +2795,8 @@ 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 +2807,15 @@ /// \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, 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 +2826,15 @@ /// \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; Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -8112,7 +8112,8 @@ 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, @@ -8181,8 +8182,9 @@ /// \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); + 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, Index: lib/AST/OpenMPClause.cpp =================================================================== --- lib/AST/OpenMPClause.cpp +++ lib/AST/OpenMPClause.cpp @@ -400,10 +400,12 @@ 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()); + TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc, + VL.size()); Clause->setVarRefs(VL); Clause->setMapTypeModifier(TypeModifier); Clause->setMapType(Type); Index: lib/Parse/ParseOpenMP.cpp =================================================================== --- lib/Parse/ParseOpenMP.cpp +++ lib/Parse/ParseOpenMP.cpp @@ -884,6 +884,7 @@ 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; @@ -934,7 +935,8 @@ 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)) { @@ -998,9 +1000,11 @@ ConsumeToken(); } else { MapType = OMPC_MAP_tofrom; + MapTypeIsImplicit = true; } } else { MapType = OMPC_MAP_tofrom; + MapTypeIsImplicit = true; } } else { UnexpectedId = true; @@ -1081,6 +1085,7 @@ ReductionIdScopeSpec, ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) : DeclarationNameInfo(), - DepKind, LinearModifier, MapTypeModifier, MapType, DepLinMapLoc); + DepKind, LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, + DepLinMapLoc); } Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -6503,7 +6503,8 @@ SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, - OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { + OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, + SourceLocation DepLinMapLoc) { OMPClause *Res = nullptr; switch (Kind) { case OMPC_private: @@ -6544,8 +6545,9 @@ 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: @@ -8464,8 +8466,9 @@ OMPClause *Sema::ActOnOpenMPMapClause( OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, - SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef VarList, - SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { + bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, + ArrayRef VarList, SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation EndLoc) { SmallVector Vars; for (auto &RE : VarList) { @@ -8580,8 +8583,7 @@ 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 << + (IsMapTypeImplicit ? 1 : 0) << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) << getOpenMPDirectiveName(DKind); // Proceed to add the variable in a map clause anyway, to prevent @@ -8597,8 +8599,7 @@ !(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 << + (IsMapTypeImplicit ? 1 : 0) << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) << getOpenMPDirectiveName(DKind); // Proceed to add the variable in a map clause anyway, to prevent @@ -8613,7 +8614,8 @@ return nullptr; return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, - MapTypeModifier, MapType, MapLoc); + MapTypeModifier, MapType, IsMapTypeImplicit, + MapLoc); } OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -1660,10 +1660,11 @@ /// 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, + 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); } @@ -7847,9 +7848,9 @@ 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 Index: test/OpenMP/target_enter_data_map_messages.c =================================================================== --- test/OpenMP/target_enter_data_map_messages.c +++ test/OpenMP/target_enter_data_map_messages.c @@ -5,6 +5,7 @@ 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) Index: test/OpenMP/target_exit_data_map_messages.c =================================================================== --- test/OpenMP/target_exit_data_map_messages.c +++ test/OpenMP/target_exit_data_map_messages.c @@ -5,6 +5,7 @@ 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)