Author: Alexey Bataev Date: 2020-06-18T13:17:03-04:00 New Revision: 437cbad3b35c7cf0f49d2bcea05555a521651113
URL: https://github.com/llvm/llvm-project/commit/437cbad3b35c7cf0f49d2bcea05555a521651113 DIFF: https://github.com/llvm/llvm-project/commit/437cbad3b35c7cf0f49d2bcea05555a521651113.diff LOG: [OPENMP]Fix PR46357: Do not allow types declarations in pragmas. Summary: Compiler may erroneously treat current context in OpenMP pragmas as the context where new type declaration/definition is allowed. But the declartation/definition of the new types in OpenMP pragmas should not be allowed. Reviewers: jdoerfert Subscribers: yaxunl, guansong, sstefan1, cfe-commits, caomhin Tags: #clang Differential Revision: https://reviews.llvm.org/D82019 Added: Modified: clang/include/clang/Parse/RAIIObjectsForParser.h clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseOpenMP.cpp clang/test/OpenMP/declare_reduction_ast_print.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Parse/RAIIObjectsForParser.h b/clang/include/clang/Parse/RAIIObjectsForParser.h index 40351bf71d9f..bc1754614ad9 100644 --- a/clang/include/clang/Parse/RAIIObjectsForParser.h +++ b/clang/include/clang/Parse/RAIIObjectsForParser.h @@ -294,9 +294,9 @@ namespace clang { bool OldVal; public: - ParsingOpenMPDirectiveRAII(Parser &P) + ParsingOpenMPDirectiveRAII(Parser &P, bool Value = true) : P(P), OldVal(P.OpenMPDirectiveParsing) { - P.OpenMPDirectiveParsing = true; + P.OpenMPDirectiveParsing = Value; } /// This can be used to restore the state early, before the dtor diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 5c41fe7921a6..7a8a94203190 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1681,7 +1681,8 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); Sema::TagUseKind TUK; - if (isDefiningTypeSpecifierContext(DSC) == AllowDefiningTypeSpec::No) + if (isDefiningTypeSpecifierContext(DSC) == AllowDefiningTypeSpec::No || + (getLangOpts().OpenMP && OpenMPDirectiveParsing)) TUK = Sema::TUK_Reference; else if (Tok.is(tok::l_brace) || (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 5161c7d06cda..6cf50a5794f7 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -1824,6 +1824,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( // Skip last tokens. skipUntilPragmaOpenMPEnd(OMPD_begin_declare_variant); + ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false); + VariantMatchInfo VMI; ASTContext &ASTCtx = Actions.getASTContext(); TI.getAsVariantMatchInfo(ASTCtx, VMI); @@ -1921,6 +1923,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc)) return DeclGroupPtrTy(); + ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false); llvm::SmallVector<Decl *, 4> Decls; DKind = parseOpenMPDirectiveKind(*this); while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) && @@ -2333,6 +2336,7 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { // FIXME: We create a bogus CompoundStmt scope to hold the contents of // the captured region. Code elsewhere assumes that any FunctionScopeInfo // should have at least one compound statement scope within it. + ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false); AssociatedStmt = (Sema::CompoundScopeRAII(Actions), ParseStatement()); AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); } else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data || diff --git a/clang/test/OpenMP/declare_reduction_ast_print.cpp b/clang/test/OpenMP/declare_reduction_ast_print.cpp index 8de954efd9e7..b46e1c8da084 100644 --- a/clang/test/OpenMP/declare_reduction_ast_print.cpp +++ b/clang/test/OpenMP/declare_reduction_ast_print.cpp @@ -17,7 +17,11 @@ namespace N1 { struct A { int a; A() : a(0) {} }; #pragma omp declare reduction(+: A : bar(omp_out, omp_in)) -}; + #pragma omp declare reduction(-: struct A : bar(omp_out, omp_in)) +} +// CHECK: namespace N1 { +// CHECK: #pragma omp declare reduction (+ : N1::A : bar(omp_out, omp_in)) +// CHECK: #pragma omp declare reduction (- : struct A : bar(omp_out, omp_in)) #pragma omp declare reduction(+ : int, char : omp_out *= omp_in) // CHECK: #pragma omp declare reduction (+ : int : omp_out *= omp_in){{$}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits