1c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev//===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===// 2c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// 3c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// The LLVM Compiler Infrastructure 4c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// 5c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// This file is distributed under the University of Illinois Open Source 6c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// License. See LICENSE.TXT for details. 7c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// 8c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev//===----------------------------------------------------------------------===// 9c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev/// \file 10c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev/// \brief This file implements parsing of all OpenMP directives and clauses. 11c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev/// 12c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev//===----------------------------------------------------------------------===// 13c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 14651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "RAIIObjectsForParser.h" 156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "clang/AST/ASTConsumer.h" 166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "clang/AST/ASTContext.h" 174fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev#include "clang/AST/StmtOpenMP.h" 18c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#include "clang/Parse/ParseDiagnostic.h" 196af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#include "clang/Parse/Parser.h" 206af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#include "clang/Sema/Scope.h" 216af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#include "llvm/ADT/PointerIntPair.h" 22c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevusing namespace clang; 23c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 24c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev//===----------------------------------------------------------------------===// 25c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev// OpenMP declarative directives. 26c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev//===----------------------------------------------------------------------===// 27c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 28ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstatic OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { 29ef8225444452a1486bd721f3285301fe84643b00Stephen Hines auto Tok = P.getCurToken(); 30ef8225444452a1486bd721f3285301fe84643b00Stephen Hines auto DKind = 31ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Tok.isAnnotation() 32ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ? OMPD_unknown 33ef8225444452a1486bd721f3285301fe84643b00Stephen Hines : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok)); 34ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (DKind == OMPD_parallel) { 35ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Tok = P.getPreprocessor().LookAhead(0); 36ef8225444452a1486bd721f3285301fe84643b00Stephen Hines auto SDKind = 37ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Tok.isAnnotation() 38ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ? OMPD_unknown 39ef8225444452a1486bd721f3285301fe84643b00Stephen Hines : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok)); 40ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (SDKind == OMPD_for) { 41ef8225444452a1486bd721f3285301fe84643b00Stephen Hines P.ConsumeToken(); 42ef8225444452a1486bd721f3285301fe84643b00Stephen Hines DKind = OMPD_parallel_for; 43ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } else if (SDKind == OMPD_sections) { 44ef8225444452a1486bd721f3285301fe84643b00Stephen Hines P.ConsumeToken(); 45ef8225444452a1486bd721f3285301fe84643b00Stephen Hines DKind = OMPD_parallel_sections; 46ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 47ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 48ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return DKind; 49ef8225444452a1486bd721f3285301fe84643b00Stephen Hines} 50ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 516af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// \brief Parsing of declarative OpenMP directives. 526af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// 536af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// threadprivate-directive: 546af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// annot_pragma_openmp 'threadprivate' simple-variable-list 55c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev/// 56c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey BataevParser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { 57c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); 588fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev ParenBraceBracketBalancer BalancerRAIIObj(*this); 59c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 60c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev SourceLocation Loc = ConsumeToken(); 616af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev SmallVector<Expr *, 5> Identifiers; 62ef8225444452a1486bd721f3285301fe84643b00Stephen Hines auto DKind = ParseOpenMPDirectiveKind(*this); 636af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev 646af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev switch (DKind) { 65c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev case OMPD_threadprivate: 66c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev ConsumeToken(); 676af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) { 68c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // The last seen token is annot_pragma_openmp_end - need to check for 69c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // extra tokens. 70c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev if (Tok.isNot(tok::annot_pragma_openmp_end)) { 71c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev Diag(Tok, diag::warn_omp_extra_tokens_at_eol) 72ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(OMPD_threadprivate); 738fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); 74c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } 756af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev // Skip the last annot_pragma_openmp_end. 76c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev ConsumeToken(); 77ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); 78c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } 79c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev break; 80c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev case OMPD_unknown: 81c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev Diag(Tok, diag::err_omp_unknown_directive); 82c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev break; 834fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPD_parallel: 84651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case OMPD_simd: 854fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPD_task: 86ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_for: 87ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_sections: 88ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_section: 89ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_single: 90ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_parallel_for: 91ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_parallel_sections: 92c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev Diag(Tok, diag::err_omp_unexpected_directive) 93ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(DKind); 94c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev break; 95c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } 968fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end); 97c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev return DeclGroupPtrTy(); 98c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev} 99c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 1004fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// \brief Parsing of declarative or executable OpenMP directives. 1014fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 1024fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// threadprivate-directive: 1034fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// annot_pragma_openmp 'threadprivate' simple-variable-list 1044fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// annot_pragma_openmp_end 1054fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 106ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// executable-directive: 107ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | 108ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'section' | 'single' | 'parallel for' | 'parallel sections' {clause} 109ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// annot_pragma_openmp_end 1104fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 1114fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey BataevStmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { 1124fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); 1138fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev ParenBraceBracketBalancer BalancerRAIIObj(*this); 1144fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SmallVector<Expr *, 5> Identifiers; 1154fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SmallVector<OMPClause *, 5> Clauses; 1166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> 117ef8225444452a1486bd721f3285301fe84643b00Stephen Hines FirstClauses(OMPC_unknown + 1); 118ef8225444452a1486bd721f3285301fe84643b00Stephen Hines unsigned ScopeFlags = 119ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; 1204fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SourceLocation Loc = ConsumeToken(), EndLoc; 121ef8225444452a1486bd721f3285301fe84643b00Stephen Hines auto DKind = ParseOpenMPDirectiveKind(*this); 1220c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev // Name of critical directive. 1230c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev DeclarationNameInfo DirName; 1244fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev StmtResult Directive = StmtError(); 1254fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 1264fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev switch (DKind) { 1274fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPD_threadprivate: 1284fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ConsumeToken(); 1294fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) { 1304fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // The last seen token is annot_pragma_openmp_end - need to check for 1314fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // extra tokens. 1324fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (Tok.isNot(tok::annot_pragma_openmp_end)) { 1334fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Diag(Tok, diag::warn_omp_extra_tokens_at_eol) 134ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(OMPD_threadprivate); 1358fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); 1364fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 1374fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev DeclGroupPtrTy Res = 138ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); 1394fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); 1404fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 1418fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end); 1424fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 143651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case OMPD_parallel: 144ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_simd: 145ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_for: 146ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_sections: 147ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_single: 148ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_section: 149ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_parallel_for: 150ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPD_parallel_sections: { 1514fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ConsumeToken(); 1520c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev 153ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (isOpenMPLoopDirective(DKind)) 154ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ScopeFlags |= Scope::OpenMPLoopDirectiveScope; 155ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (isOpenMPSimdDirective(DKind)) 156ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ScopeFlags |= Scope::OpenMPSimdDirectiveScope; 157ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ParseScope OMPDirectiveScope(this, ScopeFlags); 158ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); 1590c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev 1604fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev while (Tok.isNot(tok::annot_pragma_openmp_end)) { 161ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OpenMPClauseKind CKind = Tok.isAnnotation() 162ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ? OMPC_unknown 163ef8225444452a1486bd721f3285301fe84643b00Stephen Hines : getOpenMPClauseKind(PP.getSpelling(Tok)); 164ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OMPClause *Clause = 165ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); 1664fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev FirstClauses[CKind].setInt(true); 1674fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (Clause) { 1684fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev FirstClauses[CKind].setPointer(Clause); 1694fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Clauses.push_back(Clause); 1704fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 1714fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 1724fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Skip ',' if any. 1734fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (Tok.is(tok::comma)) 1744fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ConsumeToken(); 1754fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 1764fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // End location of the directive. 1774fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev EndLoc = Tok.getLocation(); 1784fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Consume final annot_pragma_openmp_end. 1794fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ConsumeToken(); 1804fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 1814fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev StmtResult AssociatedStmt; 1824fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev bool CreateDirective = true; 1834fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev { 1844fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // The body is a block scope like in Lambdas and Blocks. 1854fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Sema::CompoundScopeRAII CompoundScope(Actions); 186ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); 1874fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Actions.ActOnStartOfCompoundStmt(); 1884fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Parse statement 1894fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev AssociatedStmt = ParseStatement(); 1904fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Actions.ActOnFinishOfCompoundStmt(); 1914fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (!AssociatedStmt.isUsable()) { 1924fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Actions.ActOnCapturedRegionError(); 1934fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev CreateDirective = false; 1944fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } else { 195ef8225444452a1486bd721f3285301fe84643b00Stephen Hines AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.get()); 1964fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev CreateDirective = AssociatedStmt.isUsable(); 1974fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 1984fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 1994fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (CreateDirective) 200ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Directive = Actions.ActOnOpenMPExecutableDirective( 201ef8225444452a1486bd721f3285301fe84643b00Stephen Hines DKind, Clauses, AssociatedStmt.get(), Loc, EndLoc); 2024fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 2034fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Exit scope. 2040c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev Actions.EndOpenMPDSABlock(Directive.get()); 2054fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OMPDirectiveScope.Exit(); 2064fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 207ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 2084fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPD_unknown: 2094fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Diag(Tok, diag::err_omp_unknown_directive); 2108fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end); 2114fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 2124fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPD_task: 2134fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Diag(Tok, diag::err_omp_unexpected_directive) 214ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(DKind); 2158fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end); 2164fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 2174fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 2184fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev return Directive; 2194fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev} 2204fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 221c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev/// \brief Parses list of simple variables for '#pragma omp threadprivate' 2226af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// directive. 2236af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// 2246af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// simple-variable-list: 2256af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev/// '(' id-expression {, id-expression} ')' 226c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev/// 2276af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataevbool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, 2286af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev SmallVectorImpl<Expr *> &VarList, 2296af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev bool AllowScopeSpecifier) { 2306af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev VarList.clear(); 231c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // Parse '('. 2326af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); 2334fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (T.expectAndConsume(diag::err_expected_lparen_after, 2344fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev getOpenMPDirectiveName(Kind))) 2354fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev return true; 2364fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev bool IsCorrect = true; 2376af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev bool NoIdentIsFound = true; 238c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 239c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // Read tokens while ')' or annot_pragma_openmp_end is not found. 2406af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) { 241c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev CXXScopeSpec SS; 242c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev SourceLocation TemplateKWLoc; 243c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev UnqualifiedId Name; 244c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // Read var name. 245c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev Token PrevTok = Tok; 2466af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev NoIdentIsFound = false; 247c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 2486af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev if (AllowScopeSpecifier && getLangOpts().CPlusPlus && 2496af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) { 250c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev IsCorrect = false; 251c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, 2528fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev StopBeforeMatch); 2536af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(), 2546af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev TemplateKWLoc, Name)) { 2556af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev IsCorrect = false; 2566af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, 2578fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev StopBeforeMatch); 2586af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && 2596af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev Tok.isNot(tok::annot_pragma_openmp_end)) { 260c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev IsCorrect = false; 261c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, 2628fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev StopBeforeMatch); 263651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Diag(PrevTok.getLocation(), diag::err_expected) 264651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines << tok::identifier 265651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines << SourceRange(PrevTok.getLocation(), PrevTokLocation); 266c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } else { 2676af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name); 268ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ExprResult Res = 269ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo); 2706af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev if (Res.isUsable()) 271ef8225444452a1486bd721f3285301fe84643b00Stephen Hines VarList.push_back(Res.get()); 272c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } 273c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // Consume ','. 274c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev if (Tok.is(tok::comma)) { 275c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev ConsumeToken(); 276c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } 2776af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev } 278c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 2796af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev if (NoIdentIsFound) { 280651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Diag(Tok, diag::err_expected) << tok::identifier; 2816af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev IsCorrect = false; 282c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev } 283c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev 2846af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev // Parse ')'. 2854fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev IsCorrect = !T.consumeClose() && IsCorrect; 2866af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev 2876af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev return !IsCorrect && VarList.empty(); 288c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev} 2894fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 2904fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// \brief Parsing of OpenMP clauses. 2914fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 2924fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// clause: 293651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// if-clause | num_threads-clause | safelen-clause | default-clause | 2946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// private-clause | firstprivate-clause | shared-clause | linear-clause | 295ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// aligned-clause | collapse-clause | lastprivate-clause | 296ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// reduction-clause | proc_bind-clause | schedule-clause | 297ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// copyin-clause | copyprivate-clause 2984fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 2994fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey BataevOMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, 3004fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OpenMPClauseKind CKind, bool FirstClause) { 3016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines OMPClause *Clause = nullptr; 3024fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev bool ErrorFound = false; 3034fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Check if clause is allowed for the given directive. 3044fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { 305ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) 306ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(DKind); 3074fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ErrorFound = true; 3084fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 3094fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 3104fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev switch (CKind) { 311651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case OMPC_if: 312651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case OMPC_num_threads: 313651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case OMPC_safelen: 3146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines case OMPC_collapse: 315651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // OpenMP [2.5, Restrictions] 316651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // At most one if clause can appear on the directive. 317651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // At most one num_threads clause can appear on the directive. 318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // OpenMP [2.8.1, simd construct, Restrictions] 3196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // Only one safelen clause can appear on a simd directive. 3206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // Only one collapse clause can appear on a simd directive. 321651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (!FirstClause) { 322ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) 323ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPClauseName(CKind); 324651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 325651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 326651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Clause = ParseOpenMPSingleExprClause(CKind); 327651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines break; 3284fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPC_default: 3296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines case OMPC_proc_bind: 330651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // OpenMP [2.14.3.1, Restrictions] 331651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // Only a single default clause may be specified on a parallel, task or 332651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // teams directive. 3336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // OpenMP [2.5, parallel Construct, Restrictions] 3346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // At most one proc_bind clause can appear on the directive. 3354fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (!FirstClause) { 336ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) 337ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPClauseName(CKind); 3384fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 3394fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 3404fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Clause = ParseOpenMPSimpleClause(CKind); 3414fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 342ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_schedule: 343ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // OpenMP [2.7.1, Restrictions, p. 3] 344ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Only one schedule clause can appear on a loop directive. 345ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (!FirstClause) { 346ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) 347ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPClauseName(CKind); 348ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 349ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 350ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Clause = ParseOpenMPSingleExprWithArgClause(CKind); 351ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 352ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_ordered: 353ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_nowait: 354ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // OpenMP [2.7.1, Restrictions, p. 9] 355ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Only one ordered clause can appear on a loop directive. 356ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // OpenMP [2.7.1, Restrictions, C/C++, p. 4] 357ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Only one nowait clause can appear on a for directive. 358ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (!FirstClause) { 359ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) 360ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPClauseName(CKind); 361ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 362ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 363ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Clause = ParseOpenMPClause(CKind); 364ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 3654fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPC_private: 366d195bc38fd424b0c928e3c354038a8ca6e2ccac3Alexey Bataev case OMPC_firstprivate: 367ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_lastprivate: 3680c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev case OMPC_shared: 369ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_reduction: 3706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines case OMPC_linear: 371ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_aligned: 372651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case OMPC_copyin: 373ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case OMPC_copyprivate: 3744fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Clause = ParseOpenMPVarListClause(CKind); 3754fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 3764fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPC_unknown: 3774fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Diag(Tok, diag::warn_omp_extra_tokens_at_eol) 378ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(DKind); 3798fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); 3804fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 3814fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev case OMPC_threadprivate: 382ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) 383ef8225444452a1486bd721f3285301fe84643b00Stephen Hines << getOpenMPDirectiveName(DKind); 3848fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); 3854fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev break; 3864fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 3876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return ErrorFound ? nullptr : Clause; 3884fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev} 3894fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 390651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// \brief Parsing of OpenMP clauses with single expressions like 'if', 391651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or 392651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 'thread_limit'. 393651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 394651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// if-clause: 395651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 'if' '(' expression ')' 396651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 397651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// num_threads-clause: 398651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 'num_threads' '(' expression ')' 399651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 400651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// safelen-clause: 401651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 'safelen' '(' expression ')' 402651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// 4036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// collapse-clause: 4046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// 'collapse' '(' expression ')' 4056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// 406651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesOMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { 407651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation Loc = ConsumeToken(); 408651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 409651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); 410651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (T.expectAndConsume(diag::err_expected_lparen_after, 411651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines getOpenMPClauseName(Kind))) 4126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 413651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 414651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); 415651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); 416651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 417651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // Parse ')'. 418651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines T.consumeClose(); 419651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 420651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (Val.isInvalid()) 4216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 422651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 423ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return Actions.ActOnOpenMPSingleExprClause( 424ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation()); 425651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 426651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 4276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. 4284fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 4294fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// default-clause: 4304fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 'default' '(' 'none' | 'shared' ') 4314fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 4326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// proc_bind-clause: 4336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// 'proc_bind' '(' 'master' | 'close' | 'spread' ') 4346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// 4354fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey BataevOMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { 4364fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SourceLocation Loc = Tok.getLocation(); 4374fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SourceLocation LOpen = ConsumeToken(); 4384fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Parse '('. 4394fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); 4404fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (T.expectAndConsume(diag::err_expected_lparen_after, 4414fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev getOpenMPClauseName(Kind))) 4426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 4434fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 444ef8225444452a1486bd721f3285301fe84643b00Stephen Hines unsigned Type = getOpenMPSimpleClauseType( 445ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); 4464fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SourceLocation TypeLoc = Tok.getLocation(); 4474fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && 4484fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Tok.isNot(tok::annot_pragma_openmp_end)) 4494fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ConsumeAnyToken(); 4504fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 4514fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Parse ')'. 4524fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev T.consumeClose(); 4534fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 4544fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, 4554fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Tok.getLocation()); 4564fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev} 4574fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 458ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// \brief Parsing of OpenMP clauses like 'ordered'. 459ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 460ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// ordered-clause: 461ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'ordered' 462ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 463ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// nowait-clause: 464ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'nowait' 465ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 466ef8225444452a1486bd721f3285301fe84643b00Stephen HinesOMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { 467ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation Loc = Tok.getLocation(); 468ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ConsumeAnyToken(); 469ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 470ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); 471ef8225444452a1486bd721f3285301fe84643b00Stephen Hines} 472ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 473ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 474ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// \brief Parsing of OpenMP clauses with single expressions and some additional 475ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// argument like 'schedule' or 'dist_schedule'. 476ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 477ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// schedule-clause: 478ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'schedule' '(' kind [',' expression ] ')' 479ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 480ef8225444452a1486bd721f3285301fe84643b00Stephen HinesOMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { 481ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation Loc = ConsumeToken(); 482ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation CommaLoc; 483ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Parse '('. 484ef8225444452a1486bd721f3285301fe84643b00Stephen Hines BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); 485ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (T.expectAndConsume(diag::err_expected_lparen_after, 486ef8225444452a1486bd721f3285301fe84643b00Stephen Hines getOpenMPClauseName(Kind))) 487ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return nullptr; 488ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 489ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ExprResult Val; 490ef8225444452a1486bd721f3285301fe84643b00Stephen Hines unsigned Type = getOpenMPSimpleClauseType( 491ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); 492ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation KLoc = Tok.getLocation(); 493ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && 494ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Tok.isNot(tok::annot_pragma_openmp_end)) 495ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ConsumeAnyToken(); 496ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 497ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (Kind == OMPC_schedule && 498ef8225444452a1486bd721f3285301fe84643b00Stephen Hines (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic || 499ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Type == OMPC_SCHEDULE_guided) && 500ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Tok.is(tok::comma)) { 501ef8225444452a1486bd721f3285301fe84643b00Stephen Hines CommaLoc = ConsumeAnyToken(); 502ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); 503ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); 504ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (Val.isInvalid()) 505ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return nullptr; 506ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 507ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 508ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Parse ')'. 509ef8225444452a1486bd721f3285301fe84643b00Stephen Hines T.consumeClose(); 510ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 511ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return Actions.ActOnOpenMPSingleExprWithArgClause( 512ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc, 513ef8225444452a1486bd721f3285301fe84643b00Stephen Hines T.getCloseLocation()); 514ef8225444452a1486bd721f3285301fe84643b00Stephen Hines} 515ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 516ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesstatic bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, 517ef8225444452a1486bd721f3285301fe84643b00Stephen Hines UnqualifiedId &ReductionId) { 518ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation TemplateKWLoc; 519ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (ReductionIdScopeSpec.isEmpty()) { 520ef8225444452a1486bd721f3285301fe84643b00Stephen Hines auto OOK = OO_None; 521ef8225444452a1486bd721f3285301fe84643b00Stephen Hines switch (P.getCurToken().getKind()) { 522ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::plus: 523ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_Plus; 524ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 525ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::minus: 526ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_Minus; 527ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 528ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::star: 529ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_Star; 530ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 531ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::amp: 532ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_Amp; 533ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 534ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::pipe: 535ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_Pipe; 536ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 537ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::caret: 538ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_Caret; 539ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 540ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::ampamp: 541ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_AmpAmp; 542ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 543ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case tok::pipepipe: 544ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OOK = OO_PipePipe; 545ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 546ef8225444452a1486bd721f3285301fe84643b00Stephen Hines default: 547ef8225444452a1486bd721f3285301fe84643b00Stephen Hines break; 548ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 549ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (OOK != OO_None) { 550ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation OpLoc = P.ConsumeToken(); 551ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; 552ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); 553ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return false; 554ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 555ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 556ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, 557ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /*AllowDestructorName*/ false, 558ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /*AllowConstructorName*/ false, ParsedType(), 559ef8225444452a1486bd721f3285301fe84643b00Stephen Hines TemplateKWLoc, ReductionId); 560ef8225444452a1486bd721f3285301fe84643b00Stephen Hines} 561ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 562ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', 5634fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 'shared', 'copyin', or 'reduction'. 5644fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 5654fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// private-clause: 5664fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 'private' '(' list ')' 567d195bc38fd424b0c928e3c354038a8ca6e2ccac3Alexey Bataev/// firstprivate-clause: 568d195bc38fd424b0c928e3c354038a8ca6e2ccac3Alexey Bataev/// 'firstprivate' '(' list ')' 569ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// lastprivate-clause: 570ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'lastprivate' '(' list ')' 5710c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev/// shared-clause: 5720c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev/// 'shared' '(' list ')' 5736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// linear-clause: 5746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines/// 'linear' '(' list [ ':' linear-step ] ')' 575ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// aligned-clause: 576ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'aligned' '(' list [ ':' alignment ] ')' 577ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// reduction-clause: 578ef8225444452a1486bd721f3285301fe84643b00Stephen Hines/// 'reduction' '(' reduction-identifier ':' list ')' 5794fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev/// 5804fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey BataevOMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) { 5814fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SourceLocation Loc = Tok.getLocation(); 5824fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SourceLocation LOpen = ConsumeToken(); 5836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation ColonLoc = SourceLocation(); 584ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Optional scope specifier and unqualified id for reduction identifier. 585ef8225444452a1486bd721f3285301fe84643b00Stephen Hines CXXScopeSpec ReductionIdScopeSpec; 586ef8225444452a1486bd721f3285301fe84643b00Stephen Hines UnqualifiedId ReductionId; 587ef8225444452a1486bd721f3285301fe84643b00Stephen Hines bool InvalidReductionId = false; 5884fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Parse '('. 5894fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); 5904fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (T.expectAndConsume(diag::err_expected_lparen_after, 5914fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev getOpenMPClauseName(Kind))) 5926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 5934fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 594ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Handle reduction-identifier for reduction clause. 595ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (Kind == OMPC_reduction) { 596ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ColonProtectionRAIIObject ColonRAII(*this); 597ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (getLangOpts().CPlusPlus) { 598ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false); 599ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 600ef8225444452a1486bd721f3285301fe84643b00Stephen Hines InvalidReductionId = 601ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ParseReductionId(*this, ReductionIdScopeSpec, ReductionId); 602ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (InvalidReductionId) { 603ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, 604ef8225444452a1486bd721f3285301fe84643b00Stephen Hines StopBeforeMatch); 605ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 606ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (Tok.is(tok::colon)) { 607ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ColonLoc = ConsumeToken(); 608ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } else { 609ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; 610ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 611ef8225444452a1486bd721f3285301fe84643b00Stephen Hines } 612ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 6134fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SmallVector<Expr *, 5> Vars; 614ef8225444452a1486bd721f3285301fe84643b00Stephen Hines bool IsComma = !InvalidReductionId; 615ef8225444452a1486bd721f3285301fe84643b00Stephen Hines const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); 6166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && 6174fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev Tok.isNot(tok::annot_pragma_openmp_end))) { 6186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); 6194fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Parse variable 6204fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ExprResult VarExpr = ParseAssignmentExpression(); 6214fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev if (VarExpr.isUsable()) { 622ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Vars.push_back(VarExpr.get()); 6234fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } else { 6244fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, 6258fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev StopBeforeMatch); 6264fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 6274fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Skip ',' if any 6284fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev IsComma = Tok.is(tok::comma); 6296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (IsComma) 6304fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev ConsumeToken(); 6316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines else if (Tok.isNot(tok::r_paren) && 6326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Tok.isNot(tok::annot_pragma_openmp_end) && 6336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines (!MayHaveTail || Tok.isNot(tok::colon))) 6346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Diag(Tok, diag::err_omp_expected_punc) << getOpenMPClauseName(Kind); 6356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines } 6366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 637ef8225444452a1486bd721f3285301fe84643b00Stephen Hines // Parse ':' linear-step (or ':' alignment). 6386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Expr *TailExpr = nullptr; 6396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); 6406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (MustHaveTail) { 6416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ColonLoc = Tok.getLocation(); 6426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ConsumeToken(); 6436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ExprResult Tail = ParseAssignmentExpression(); 6446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (Tail.isUsable()) 645ef8225444452a1486bd721f3285301fe84643b00Stephen Hines TailExpr = Tail.get(); 6466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines else 6476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, 6486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines StopBeforeMatch); 6494fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev } 6504fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 6514fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev // Parse ')'. 6524fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev T.consumeClose(); 653ef8225444452a1486bd721f3285301fe84643b00Stephen Hines if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId) 6546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 6554fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 656ef8225444452a1486bd721f3285301fe84643b00Stephen Hines return Actions.ActOnOpenMPVarListClause( 657ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(), 658ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ReductionIdScopeSpec, 659ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) 660ef8225444452a1486bd721f3285301fe84643b00Stephen Hines : DeclarationNameInfo()); 6614fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev} 6624fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev 663