[clang] 9e9f6eb - [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 24 12:54:16 PDT 2021


Author: Alexey Bataev
Date: 2021-03-24T12:53:33-07:00
New Revision: 9e9f6eba84f01785ef154539878a7ebd2692344a

URL: https://github.com/llvm/llvm-project/commit/9e9f6eba84f01785ef154539878a7ebd2692344a
DIFF: https://github.com/llvm/llvm-project/commit/9e9f6eba84f01785ef154539878a7ebd2692344a.diff

LOG: [OPENMP]Fix PR49468: Declare target should allow empty sequences and namespaces.

The emty declare target/end declare target region should not cause an
error emission.

Differential Revision: https://reviews.llvm.org/D99288

Added: 
    

Modified: 
    clang/lib/Parse/ParseOpenMP.cpp
    clang/test/OpenMP/declare_target_ast_print.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 2e0104e3d348..1ea01409d3d3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2115,9 +2115,18 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 
     ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false);
     llvm::SmallVector<Decl *, 4> Decls;
-    DKind = parseOpenMPDirectiveKind(*this);
-    while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) &&
-           Tok.isNot(tok::r_brace)) {
+    while (Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
+      if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
+        TentativeParsingAction TPA(*this);
+        ConsumeAnnotationToken();
+        DKind = parseOpenMPDirectiveKind(*this);
+        if (DKind != OMPD_end_declare_target)
+          TPA.Revert();
+        else
+          TPA.Commit();
+      }
+      if (DKind == OMPD_end_declare_target)
+        break;
       DeclGroupPtrTy Ptr;
       // Here we expect to see some function declaration.
       if (AS == AS_none) {
@@ -2133,15 +2142,6 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
         DeclGroupRef Ref = Ptr.get();
         Decls.append(Ref.begin(), Ref.end());
       }
-      if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
-        TentativeParsingAction TPA(*this);
-        ConsumeAnnotationToken();
-        DKind = parseOpenMPDirectiveKind(*this);
-        if (DKind != OMPD_end_declare_target)
-          TPA.Revert();
-        else
-          TPA.Commit();
-      }
     }
 
     ParseOMPEndDeclareTargetDirective(DKind, DTLoc);

diff  --git a/clang/test/OpenMP/declare_target_ast_print.cpp b/clang/test/OpenMP/declare_target_ast_print.cpp
index c086f8526147..dbd0b923a7d6 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -277,4 +277,8 @@ int main (int argc, char **argv) {
 // CHECK-NEXT: int ts = 1;
 // CHECK-NEXT: #pragma omp end declare target
 
+// Do not expect anything here since the region is empty.
+#pragma omp declare target
+#pragma omp end declare target
+
 #endif


        


More information about the cfe-commits mailing list