]> granicus.if.org Git - clang/commitdiff
[OPENMP] Initial parsing and sema analysis for 'section' directive.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 26 Jun 2014 08:21:58 +0000 (08:21 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 26 Jun 2014 08:21:58 +0000 (08:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211767 91177308-0d34-0410-b5e6-96231b3b80d8

27 files changed:
include/clang-c/Index.h
include/clang/AST/DataRecursiveASTVisitor.h
include/clang/AST/RecursiveASTVisitor.h
include/clang/AST/StmtOpenMP.h
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Basic/OpenMPKinds.def
include/clang/Basic/StmtNodes.td
include/clang/Sema/Sema.h
include/clang/Serialization/ASTBitCodes.h
lib/AST/Stmt.cpp
lib/AST/StmtPrinter.cpp
lib/AST/StmtProfile.cpp
lib/Basic/OpenMPKinds.cpp
lib/CodeGen/CGStmt.cpp
lib/CodeGen/CGStmtOpenMP.cpp
lib/CodeGen/CodeGenFunction.h
lib/Parse/ParseOpenMP.cpp
lib/Sema/SemaOpenMP.cpp
lib/Sema/TreeTransform.h
lib/Serialization/ASTReaderStmt.cpp
lib/Serialization/ASTWriterStmt.cpp
lib/StaticAnalyzer/Core/ExprEngine.cpp
test/OpenMP/nesting_of_regions.cpp
test/OpenMP/sections_ast_print.cpp
test/OpenMP/sections_misc_messages.c
tools/libclang/CIndex.cpp
tools/libclang/CXCursor.cpp

index 567522e044747318a210854e01cc83414916bb6f..909e2dbfe276ec95fa5bf0b73901af1b22791466 100644 (file)
@@ -2147,7 +2147,11 @@ enum CXCursorKind {
    */
   CXCursor_OMPSectionsDirective          = 235,
 
-  CXCursor_LastStmt                      = CXCursor_OMPSectionsDirective,
+  /** \brief OpenMP section directive.
+   */
+  CXCursor_OMPSectionDirective           = 236,
+
+  CXCursor_LastStmt                      = CXCursor_OMPSectionDirective,
 
   /**
    * \brief Cursor that represents the translation unit itself.
index 9a27c3954aa980e463d555e2507615a23932619f..536d372ec457893d0f0aa677654584046ff1620c 100644 (file)
@@ -2300,6 +2300,11 @@ DEF_TRAVERSE_STMT(OMPSectionsDirective, {
     return false;
 })
 
+DEF_TRAVERSE_STMT(OMPSectionDirective, {
+  if (!TraverseOMPExecutableDirective(S))
+    return false;
+})
+
 // OpenMP clauses.
 template <typename Derived>
 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
index 9e9d4effd938115745771af50d174e121eb58863..eae370e0b86396184876ade77af3dcd5ca983ed5 100644 (file)
@@ -2322,6 +2322,11 @@ DEF_TRAVERSE_STMT(OMPSectionsDirective, {
     return false;
 })
 
+DEF_TRAVERSE_STMT(OMPSectionDirective, {
+  if (!TraverseOMPExecutableDirective(S))
+    return false;
+})
+
 // OpenMP clauses.
 template <typename Derived>
 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
index aca0274192fcd8a9e1ac7b5433d770653132d816..8b954f45e71aec474fc58841f5dc75238a1d1a99 100644 (file)
@@ -423,6 +423,53 @@ public:
   }
 };
 
+/// \brief This represents '#pragma omp section' directive.
+///
+/// \code
+/// #pragma omp section
+/// \endcode
+///
+class OMPSectionDirective : public OMPExecutableDirective {
+  friend class ASTStmtReader;
+  /// \brief Build directive with the given start and end location.
+  ///
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending location of the directive.
+  ///
+  OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc)
+      : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
+                               StartLoc, EndLoc, 0, 1) {}
+
+  /// \brief Build an empty directive.
+  ///
+  explicit OMPSectionDirective()
+      : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
+                               SourceLocation(), SourceLocation(), 0, 1) {}
+
+public:
+  /// \brief Creates directive.
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending Location of the directive.
+  /// \param AssociatedStmt Statement, associated with the directive.
+  ///
+  static OMPSectionDirective *Create(const ASTContext &C,
+                                     SourceLocation StartLoc,
+                                     SourceLocation EndLoc,
+                                     Stmt *AssociatedStmt);
+
+  /// \brief Creates an empty directive.
+  ///
+  /// \param C AST context.
+  ///
+  static OMPSectionDirective *CreateEmpty(const ASTContext &C, EmptyShell);
+
+  static bool classof(const Stmt *T) {
+    return T->getStmtClass() == OMPSectionDirectiveClass;
+  }
+};
+
 } // end namespace clang
 
 #endif
index 9be3d8543a4bc600d7c1298a89e1ef5a0ca8388d..04923dae02d5bf9f3515cc5bb5007df983c6b084 100644 (file)
@@ -7115,6 +7115,11 @@ def err_omp_prohibited_region_simd : Error<
   "OpenMP constructs may not be nested inside a simd region">;
 def err_omp_sections_not_compound_stmt : Error<
   "the statement for '#pragma omp sections' must be a compound statement">;
+def err_omp_orphaned_section_directive : Error<
+  "%select{orphaned 'omp section' directives are prohibited, it|'omp section' directive}0"
+  " must be closely nested to a sections region%select{|, not a %1 region}0">;
+def err_omp_sections_substmt_not_section : Error<
+  "statement in 'omp sections' directive must be enclosed into a section region">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
index 312b975f26e4e40219431177b905d74d7f10430e..c47782b816c3cca05d3a7329c1467787b31993c2 100644 (file)
@@ -47,6 +47,7 @@ OPENMP_DIRECTIVE(task)
 OPENMP_DIRECTIVE(simd)
 OPENMP_DIRECTIVE(for)
 OPENMP_DIRECTIVE(sections)
+OPENMP_DIRECTIVE(section)
 
 // OpenMP clauses.
 OPENMP_CLAUSE(if, OMPIfClause)
index f4ff3ef20f047661f11e9ac3f48804ec537be32f..5236f468832c1948115de74075f90fd84827d27f 100644 (file)
@@ -181,3 +181,4 @@ def OMPParallelDirective : DStmt<OMPExecutableDirective>;
 def OMPSimdDirective : DStmt<OMPExecutableDirective>;
 def OMPForDirective : DStmt<OMPExecutableDirective>;
 def OMPSectionsDirective : DStmt<OMPExecutableDirective>;
+def OMPSectionDirective : DStmt<OMPExecutableDirective>;
index 6d0eef5d56320deb1d058a870a55c11ef1ee6c7d..0a6cd33b8d446c59428119be6caa471b873e4102 100644 (file)
@@ -7327,6 +7327,10 @@ public:
   StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
                                           Stmt *AStmt, SourceLocation StartLoc,
                                           SourceLocation EndLoc);
+  /// \brief Called on well-formed '\#pragma omp section' after parsing of the
+  /// associated statement.
+  StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc,
+                                         SourceLocation EndLoc);
 
   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
                                          Expr *Expr,
index 828672e3d610fb9648e822c4d71092ccc5dc2be1..55cf34fc7309d7a00c3fa51d6034f097656e2ec6 100644 (file)
@@ -1343,6 +1343,7 @@ namespace clang {
       STMT_OMP_SIMD_DIRECTIVE,
       STMT_OMP_FOR_DIRECTIVE,
       STMT_OMP_SECTIONS_DIRECTIVE,
+      STMT_OMP_SECTION_DIRECTIVE,
 
       // ARC
       EXPR_OBJC_BRIDGED_CAST,     // ObjCBridgedCastExpr
index 48b3dc5baf4fe90b7412f5af6d94d87fbf9d0285..b402f6edd25482c3eebbef9ed9a379bfcfe67c8a 100644 (file)
@@ -1410,3 +1410,23 @@ OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
   return new (Mem) OMPSectionsDirective(NumClauses);
 }
 
+OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
+                                                 SourceLocation StartLoc,
+                                                 SourceLocation EndLoc,
+                                                 Stmt *AssociatedStmt) {
+  unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
+                                           llvm::alignOf<Stmt *>());
+  void *Mem = C.Allocate(Size + sizeof(Stmt *));
+  OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc);
+  Dir->setAssociatedStmt(AssociatedStmt);
+  return Dir;
+}
+
+OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
+                                                      EmptyShell) {
+  unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
+                                           llvm::alignOf<Stmt *>());
+  void *Mem = C.Allocate(Size + sizeof(Stmt *));
+  return new (Mem) OMPSectionDirective();
+}
+
index 46e9cbdc3d91d1791a2192ac5c4cdcd0c532e55b..0ac683347f0a4f7c936e399df181eeb4575cd4af 100644 (file)
@@ -792,6 +792,11 @@ void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
   PrintOMPExecutableDirective(Node);
 }
 
+void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
+  Indent() << "#pragma omp section";
+  PrintOMPExecutableDirective(Node);
+}
+
 //===----------------------------------------------------------------------===//
 //  Expr printing methods.
 //===----------------------------------------------------------------------===//
index 0a9a011b93ab2829c0dfe48255d781342c31f56a..804003fb6781fe6fa0e3ffc2a97e533b3ca122c5 100644 (file)
@@ -364,6 +364,10 @@ void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
   VisitOMPExecutableDirective(S);
 }
 
+void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
+  VisitOMPExecutableDirective(S);
+}
+
 void StmtProfiler::VisitExpr(const Expr *S) {
   VisitStmt(S);
 }
index 07e2222f979556e6ce1b67eef3c401f0a0347679..547eb32199b073ea2c891f8d9aa721491f05205d 100644 (file)
@@ -204,6 +204,7 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
   case OMPD_unknown:
   case OMPD_threadprivate:
   case OMPD_task:
+  case OMPD_section:
     break;
   }
   return false;
@@ -214,8 +215,8 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_for ||
-         DKind == OMPD_sections; // TODO add next directives.
+  return DKind == OMPD_for || DKind == OMPD_sections ||
+         DKind == OMPD_section; // TODO add next directives.
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
index 3e49733a9c755b8658d826025515bc4e27211b0e..c3ad8b369c2a8b5d6176e961a689df4a93afaa5d 100644 (file)
@@ -185,6 +185,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
   case Stmt::OMPSectionsDirectiveClass:
     EmitOMPSectionsDirective(cast<OMPSectionsDirective>(*S));
     break;
+  case Stmt::OMPSectionDirectiveClass:
+    EmitOMPSectionDirective(cast<OMPSectionDirective>(*S));
+    break;
   }
 }
 
index f75111bce191fd53c4115f454a6a080921b93023..ae45aa4abbfb2ee101a7b8d970f08621cf6888c5 100644 (file)
@@ -83,3 +83,7 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &) {
   llvm_unreachable("CodeGen for 'omp sections' is not supported yet.");
 }
 
+void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &) {
+  llvm_unreachable("CodeGen for 'omp section' is not supported yet.");
+}
+
index 8a7ebdd5e9b40e413da900fbf88740a72c05f783..87453992b1d3592848db832bc5efe49e8b5898c3 100644 (file)
@@ -1904,6 +1904,7 @@ public:
   void EmitOMPSimdDirective(const OMPSimdDirective &S);
   void EmitOMPForDirective(const OMPForDirective &S);
   void EmitOMPSectionsDirective(const OMPSectionsDirective &S);
+  void EmitOMPSectionDirective(const OMPSectionDirective &S);
 
   //===--------------------------------------------------------------------===//
   //                         LValue Expression Emission
index 7a3c05e96bedda1693b17e0ff1428f222133933f..11e888efb4033ffdee6205beea521d49356f5a54 100644 (file)
@@ -64,6 +64,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
   case OMPD_task:
   case OMPD_for:
   case OMPD_sections:
+  case OMPD_section:
     Diag(Tok, diag::err_omp_unexpected_directive)
         << getOpenMPDirectiveName(DKind);
     break;
@@ -79,8 +80,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
 ///         annot_pragma_openmp_end
 ///
 ///       executable-directive:
-///         annot_pragma_openmp 'parallel'|'simd'|'for'|'sections'  {clause}
-///         annot_pragma_openmp_end
+///         annot_pragma_openmp 'parallel'|'simd'|'for'|'sections'|'section'
+///         {clause} annot_pragma_openmp_end
 ///
 StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
   assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
@@ -119,7 +120,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
   case OMPD_parallel:
   case OMPD_simd:
   case OMPD_for:
-  case OMPD_sections: {
+  case OMPD_sections:
+  case OMPD_section: {
     ConsumeToken();
 
     if (isOpenMPLoopDirective(DKind))
index db471b88adf32a90007bd8ad6e3927adc284fc0a..ba441a2b14e956ed3b17e7a092ad4e53fd73513c 100644 (file)
@@ -917,6 +917,13 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, SourceLocation Loc,
     ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params);
     break;
   }
+  case OMPD_section: {
+    Sema::CapturedParamNameType Params[] = {
+        std::make_pair(StringRef(), QualType()) // __context with shared vars
+    };
+    ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params);
+    break;
+  }
   case OMPD_threadprivate:
   case OMPD_task:
     llvm_unreachable("OpenMP Directive is not allowed");
@@ -939,6 +946,19 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
       SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd);
       return true;
     }
+    if (CurrentRegion == OMPD_section) {
+      // OpenMP [2.7.2, sections Construct, Restrictions]
+      // Orphaned section directives are prohibited. That is, the section
+      // directives must appear within the sections construct and must not be
+      // encountered elsewhere in the sections region.
+      if (ParentRegion != OMPD_sections) {
+        SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive)
+            << (ParentRegion != OMPD_unknown)
+            << getOpenMPDirectiveName(ParentRegion);
+        return true;
+      }
+      return false;
+    }
     if (isOpenMPWorksharingDirective(CurrentRegion) &&
         !isOpenMPParallelDirective(CurrentRegion) &&
         !isOpenMPSimdDirective(CurrentRegion)) {
@@ -1008,6 +1028,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
     Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc,
                                        EndLoc);
     break;
+  case OMPD_section:
+    assert(ClausesWithImplicit.empty() &&
+           "No clauses is allowed for 'omp section' directive");
+    Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc);
+    break;
   case OMPD_threadprivate:
   case OMPD_task:
     llvm_unreachable("OpenMP Directive is not allowed");
@@ -1592,7 +1617,15 @@ StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
       return StmtError();
     // All associated statements must be '#pragma omp section' except for
     // the first one.
-    // TODO
+    for (++S; S; ++S) {
+      auto SectionStmt = *S;
+      if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
+        if (SectionStmt)
+          Diag(SectionStmt->getLocStart(),
+               diag::err_omp_sections_substmt_not_section);
+        return StmtError();
+      }
+    }
   } else {
     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
     return StmtError();
@@ -1604,6 +1637,16 @@ StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
                                       AStmt);
 }
 
+StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt,
+                                             SourceLocation StartLoc,
+                                             SourceLocation EndLoc) {
+  assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
+
+  getCurFunction()->setHasBranchProtectedScope();
+
+  return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt);
+}
+
 OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
                                              SourceLocation StartLoc,
                                              SourceLocation LParenLoc,
index 2e595ea657a19da71b56c2edb0c6e64f57740954..59208737b752d321ff840cae1096895394395fc9 100644 (file)
@@ -6439,6 +6439,16 @@ TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
   return Res;
 }
 
+template <typename Derived>
+StmtResult
+TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
+  DeclarationNameInfo DirName;
+  getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr);
+  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
+  getDerived().getSema().EndOpenMPDSABlock(Res.get());
+  return Res;
+}
+
 //===----------------------------------------------------------------------===//
 // OpenMP clause transformation
 //===----------------------------------------------------------------------===//
index ef057f870f7518fecebfe2ffd5c39ad70b2ec552..6649b6f05e9aabd8176d7440e5a412bdf33b8570 100644 (file)
@@ -1913,6 +1913,11 @@ void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
   VisitOMPExecutableDirective(D);
 }
 
+void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
+  VisitStmt(D);
+  VisitOMPExecutableDirective(D);
+}
+
 //===----------------------------------------------------------------------===//
 // ASTReader Implementation
 //===----------------------------------------------------------------------===//
@@ -2413,6 +2418,10 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
           Context, Record[ASTStmtReader::NumStmtFields], Empty);
       break;
 
+    case STMT_OMP_SECTION_DIRECTIVE:
+      S = OMPSectionDirective::CreateEmpty(Context, Empty);
+      break;
+
     case EXPR_CXX_OPERATOR_CALL:
       S = new (Context) CXXOperatorCallExpr(Context, Empty);
       break;
index c0566679a5149806a103f0d336676d0822a62738..10a55b2889676e5065fe2b08ab467937600d4a47 100644 (file)
@@ -1825,6 +1825,12 @@ void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
   Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
 }
 
+void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
+  VisitStmt(D);
+  VisitOMPExecutableDirective(D);
+  Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
+}
+
 //===----------------------------------------------------------------------===//
 // ASTWriter Implementation
 //===----------------------------------------------------------------------===//
index 45250f32b98a34729472550ad41af98974ef24b1..244862d0de0b0a614adf6cdfea3ce8eaef05c000 100644 (file)
@@ -734,6 +734,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
     case Stmt::OMPSimdDirectiveClass:
     case Stmt::OMPForDirectiveClass:
     case Stmt::OMPSectionsDirectiveClass:
+    case Stmt::OMPSectionDirectiveClass:
       llvm_unreachable("Stmt should not be in analyzer evaluation loop");
 
     case Stmt::ObjCSubscriptRefExprClass:
index dc8a00257a9e590723bbbaa039ae3ab9b59eb8b1..9d0ee29ec30c4a1a93f4e018a5e26aef11c1525a 100644 (file)
@@ -6,29 +6,39 @@ template <class T>
 void foo() {
 #pragma omp parallel
 #pragma omp for
-  for (int i = 0; i < 10; ++i);
+  for (int i = 0; i < 10; ++i)
+    ;
 #pragma omp parallel
 #pragma omp simd
-  for (int i = 0; i < 10; ++i);
+  for (int i = 0; i < 10; ++i)
+    ;
 #pragma omp parallel
 #pragma omp sections
   {
     bar();
   }
+#pragma omp parallel
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a parallel region}}
+  {
+    bar();
+  }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
@@ -37,20 +47,30 @@ void foo() {
       bar();
     }
   }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
 #pragma omp for // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
 #pragma omp simd
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
@@ -59,20 +79,30 @@ void foo() {
       bar();
     }
   }
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a for region}}
+    {
+      bar();
+    }
+  }
 #pragma omp sections
   {
 #pragma omp for // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp sections
   {
 #pragma omp simd
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp sections
   {
 #pragma omp parallel
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp sections
   {
@@ -81,34 +111,55 @@ void foo() {
       bar();
     }
   }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+      bar();
+    }
+  }
+#pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}}
+  {
+    bar();
+  }
 }
 
 void foo() {
 #pragma omp parallel
 #pragma omp for
-  for (int i = 0; i < 10; ++i);
+  for (int i = 0; i < 10; ++i)
+    ;
 #pragma omp parallel
 #pragma omp simd
-  for (int i = 0; i < 10; ++i);
+  for (int i = 0; i < 10; ++i)
+    ;
 #pragma omp parallel
 #pragma omp sections
   {
     bar();
   }
+#pragma omp parallel
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a parallel region}}
+  {
+    bar();
+  }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
@@ -117,20 +168,30 @@ void foo() {
       bar();
     }
   }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
 #pragma omp for // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
 #pragma omp simd
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
@@ -139,20 +200,30 @@ void foo() {
       bar();
     }
   }
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a for region}}
+    {
+      bar();
+    }
+  }
 #pragma omp sections
   {
 #pragma omp for // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp sections
   {
 #pragma omp simd
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp sections
   {
 #pragma omp parallel
-  for (int i = 0; i < 10; ++i);
+    for (int i = 0; i < 10; ++i)
+      ;
   }
 #pragma omp sections
   {
@@ -161,6 +232,17 @@ void foo() {
       bar();
     }
   }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+      bar();
+    }
+  }
+#pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}}
+  {
+    bar();
+  }
   return foo<int>();
 }
 
index 56c1c3c988cd88928735031b2dda13ac423a4412..b1a2e030400182e112872fe296244a2509ce3136 100644 (file)
@@ -14,9 +14,9 @@ T tmain(T argc) {
   static T a;
 // CHECK: static T a;
 #pragma omp parallel
-#pragma omp sections private(argc, b), firstprivate(c, d), lastprivate(d, f) reduction (-: g) nowait
+#pragma omp sections private(argc, b), firstprivate(c, d), lastprivate(d, f) reduction(- : g) nowait
   {
-            foo();
+    foo();
   }
   // CHECK-NEXT: #pragma omp parallel
   // CHECK-NEXT: #pragma omp sections private(argc,b) firstprivate(c,d) lastprivate(d,f) reduction(-: g) nowait
@@ -31,13 +31,19 @@ int main(int argc, char **argv) {
   static int a;
 // CHECK: static int a;
 #pragma omp parallel
-#pragma omp sections private(argc, b), firstprivate(argv, c), lastprivate(d, f) reduction(+:g) nowait
+#pragma omp sections private(argc, b), firstprivate(argv, c), lastprivate(d, f) reduction(+ : g) nowait
   {
-      foo();
+#pragma omp section
+    foo();
+#pragma omp section
+    foo();
   }
   // CHECK-NEXT: #pragma omp parallel
   // CHECK-NEXT: #pragma omp sections private(argc,b) firstprivate(argv,c) lastprivate(d,f) reduction(+: g) nowait
   // CHECK-NEXT: {
+  // CHECK-NEXT: #pragma omp section
+  // CHECK-NEXT: foo();
+  // CHECK-NEXT: #pragma omp section
   // CHECK-NEXT: foo();
   // CHECK-NEXT: }
   return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
index e8aa5e28c0ed2fda0cceb03b5d0cb1b057c18218..977d154156f5b23cfbdcb3f0cb6b69677bd62bf2 100644 (file)
@@ -18,6 +18,13 @@ void test_no_clause() {
 // expected-error@+2 {{the statement for '#pragma omp sections' must be a compound statement}}
 #pragma omp sections
   ++i;
+
+#pragma omp sections
+  {
+    foo();
+    foo(); // expected-error {{statement in 'omp sections' directive must be enclosed into a section region}}
+  }
+
 }
 
 void test_branch_protected_scope() {
@@ -40,12 +47,24 @@ L1:
     L2:
       x[i]++;
     }
+#pragma omp section
+    if (i == 5)
+      goto L1; // expected-error {{use of undeclared label 'L1'}}
+    else if (i == 6)
+      return; // expected-error {{cannot return from OpenMP region}}
+    else if (i == 7)
+      goto L3;
+    else if (i == 8) {
+    L3:
+      x[i]++;
+    }
   }
 
   if (x[0] == 0)
     goto L2; // expected-error {{use of undeclared label 'L2'}}
   else if (x[1] == 1)
     goto L1;
+  goto L3; // expected-error {{use of undeclared label 'L3'}}
 }
 
 void test_invalid_clause() {
@@ -55,6 +74,9 @@ void test_invalid_clause() {
 #pragma omp sections foo bar
   {
     foo();
+// expected-error@+1 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp section'}}
+#pragma omp section nowait
+    ;
   }
 }
 
index ab0cd6fddaada150a8f5108641ab5aff43a84bae..2b7c8f50bbc4763bd80895bb67989d96de3f7176 100644 (file)
@@ -1853,6 +1853,7 @@ public:
   void VisitOMPSimdDirective(const OMPSimdDirective *D);
   void VisitOMPForDirective(const OMPForDirective *D);
   void VisitOMPSectionsDirective(const OMPSectionsDirective *D);
+  void VisitOMPSectionDirective(const OMPSectionDirective *D);
 
 private:
   void AddDeclarationNameInfo(const Stmt *S);
@@ -2292,6 +2293,10 @@ void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) {
   VisitOMPExecutableDirective(D);
 }
 
+void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) {
+  VisitOMPExecutableDirective(D);
+}
+
 void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
   EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
 }
@@ -3972,6 +3977,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
     return cxstring::createRef("OMPForDirective");
   case CXCursor_OMPSectionsDirective:
     return cxstring::createRef("OMPSectionsDirective");
+  case CXCursor_OMPSectionDirective:
+    return cxstring::createRef("OMPSectionDirective");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
index ad8c7df70b715b2ed89eeb1f3741bb78ec7844fe..8a5077c12af3e918536c274150bdb46d4c505765 100644 (file)
@@ -525,6 +525,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
   case Stmt::OMPSectionsDirectiveClass:
     K = CXCursor_OMPSectionsDirective;
     break;
+  case Stmt::OMPSectionDirectiveClass:
+    K = CXCursor_OMPSectionDirective;
+    break;
   }
 
   CXCursor C = { K, 0, { Parent, S, TU } };