[PATCH] D82019: [OPENMP]Fix PR46357: Do not allow types declarations in pragmas.

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 18 10:22:01 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG437cbad3b35c: [OPENMP]Fix PR46357: Do not allow types declarations in pragmas. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82019/new/

https://reviews.llvm.org/D82019

Files:
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/test/OpenMP/declare_reduction_ast_print.cpp


Index: clang/test/OpenMP/declare_reduction_ast_print.cpp
===================================================================
--- clang/test/OpenMP/declare_reduction_ast_print.cpp
+++ clang/test/OpenMP/declare_reduction_ast_print.cpp
@@ -17,7 +17,11 @@
 {
   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){{$}}
Index: clang/lib/Parse/ParseOpenMP.cpp
===================================================================
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -1824,6 +1824,8 @@
     // 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 @@
     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 @@
       // 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 ||
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1681,7 +1681,8 @@
 
   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)) ||
Index: clang/include/clang/Parse/RAIIObjectsForParser.h
===================================================================
--- clang/include/clang/Parse/RAIIObjectsForParser.h
+++ clang/include/clang/Parse/RAIIObjectsForParser.h
@@ -294,9 +294,9 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82019.271768.patch
Type: text/x-patch
Size: 3392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200618/aa74b5af/attachment.bin>


More information about the cfe-commits mailing list