From: Alexey Bataev Date: Fri, 6 Jul 2018 19:35:42 +0000 (+0000) Subject: [OPENMP] Make clauses closing loc point to right bracket. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8980f32f68df0b659923702e9df0b4f8538fdf4f;p=clang [OPENMP] Make clauses closing loc point to right bracket. For some of the clauses the closing location erroneously points to the beginning of the next clause rather than on the location of the closing bracket of the clause. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336460 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 29cd9e82d7..416691ccc8 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -2822,6 +2822,7 @@ public: struct OpenMPVarListDataTy { Expr *TailExpr = nullptr; SourceLocation ColonLoc; + SourceLocation RLoc; CXXScopeSpec ReductionIdScopeSpec; DeclarationNameInfo ReductionId; OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index d06e101423..a413e96a91 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -424,13 +424,15 @@ void Parser::ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm) { SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch); } else { // Match the ')'. - T.consumeClose(); + SourceLocation RLoc = Tok.getLocation(); + if (!T.consumeClose()) + RLoc = T.getCloseLocation(); assert(!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() && "Unexpected number of commas!"); - ExprResult Initializer = Actions.ActOnParenListExpr( - T.getOpenLocation(), T.getCloseLocation(), Exprs); + ExprResult Initializer = + Actions.ActOnParenListExpr(T.getOpenLocation(), RLoc, Exprs); Actions.AddInitializerToDecl(OmpPrivParm, Initializer.get(), /*DirectInit=*/true); } @@ -1378,9 +1380,10 @@ ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName, Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); // Parse ')'. - T.consumeClose(); + RLoc = Tok.getLocation(); + if (!T.consumeClose()) + RLoc = T.getCloseLocation(); - RLoc = T.getCloseLocation(); return Val; } @@ -1457,12 +1460,13 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, ConsumeAnyToken(); // Parse ')'. - T.consumeClose(); + SourceLocation RLoc = Tok.getLocation(); + if (!T.consumeClose()) + RLoc = T.getCloseLocation(); if (ParseOnly) return nullptr; - return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, - Tok.getLocation()); + return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, RLoc); } /// Parsing of OpenMP clauses like 'ordered'. @@ -1633,7 +1637,9 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind, } // Parse ')'. - T.consumeClose(); + SourceLocation RLoc = Tok.getLocation(); + if (!T.consumeClose()) + RLoc = T.getCloseLocation(); if (NeedAnExpression && Val.isInvalid()) return nullptr; @@ -1641,8 +1647,7 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind, if (ParseOnly) return nullptr; return Actions.ActOnOpenMPSingleExprWithArgClause( - Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, - T.getCloseLocation()); + Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, RLoc); } static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, @@ -1914,7 +1919,9 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, } // Parse ')'. - T.consumeClose(); + Data.RLoc = Tok.getLocation(); + if (!T.consumeClose()) + Data.RLoc = T.getCloseLocation(); return (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown && Vars.empty()) || (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || @@ -1979,7 +1986,7 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, if (ParseOnly) return nullptr; return Actions.ActOnOpenMPVarListClause( - Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Tok.getLocation(), + Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Data.RLoc, Data.ReductionIdScopeSpec, Data.ReductionId, Data.DepKind, Data.LinKind, Data.MapTypeModifier, Data.MapType, Data.IsMapTypeImplicit, Data.DepLinMapLoc); diff --git a/test/OpenMP/dump.cpp b/test/OpenMP/dump.cpp index 162136b20b..f54d25f197 100644 --- a/test/OpenMP/dump.cpp +++ b/test/OpenMP/dump.cpp @@ -44,10 +44,10 @@ struct S { }; // CHECK: | `-OMPParallelForDirective {{.+}} {{|}} -// CHECK-NEXT: | |-OMPDefaultClause {{.+}} -// CHECK-NEXT: | |-OMPPrivateClause {{.+}} +// CHECK-NEXT: | |-OMPDefaultClause {{.+}} +// CHECK-NEXT: | |-OMPPrivateClause {{.+}} // CHECK-NEXT: | | `-DeclRefExpr {{.+}} 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &' -// CHECK-NEXT: | |-OMPSharedClause {{.+}} +// CHECK-NEXT: | |-OMPSharedClause {{.+}} // CHECK-NEXT: | | `-MemberExpr {{.+}} 'int' lvalue ->b // CHECK-NEXT: | | `-CXXThisExpr {{.+}} 'S *' this // CHECK-NEXT: | |-OMPScheduleClause {{.+}}