r211767 - [OPENMP] Initial parsing and sema analysis for 'section' directive.

Michael Wong fraggamuffin at gmail.com
Mon Jul 21 11:39:29 PDT 2014


I have reviewed this while reviewing:
r212516 - [OPENMP] Parsing and sema analysis for 'omp parallel sections'
directive.


All the code is a similar pattern and looks good.


On Thu, Jun 26, 2014 at 4:21 AM, Alexey Bataev <a.bataev at hotmail.com> wrote:

> Author: abataev
> Date: Thu Jun 26 03:21:58 2014
> New Revision: 211767
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211767&view=rev
> Log:
> [OPENMP] Initial parsing and sema analysis for 'section' directive.
>
> Modified:
>     cfe/trunk/include/clang-c/Index.h
>     cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
>     cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
>     cfe/trunk/include/clang/AST/StmtOpenMP.h
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>     cfe/trunk/include/clang/Basic/OpenMPKinds.def
>     cfe/trunk/include/clang/Basic/StmtNodes.td
>     cfe/trunk/include/clang/Sema/Sema.h
>     cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>     cfe/trunk/lib/AST/Stmt.cpp
>     cfe/trunk/lib/AST/StmtPrinter.cpp
>     cfe/trunk/lib/AST/StmtProfile.cpp
>     cfe/trunk/lib/Basic/OpenMPKinds.cpp
>     cfe/trunk/lib/CodeGen/CGStmt.cpp
>     cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>     cfe/trunk/lib/CodeGen/CodeGenFunction.h
>     cfe/trunk/lib/Parse/ParseOpenMP.cpp
>     cfe/trunk/lib/Sema/SemaOpenMP.cpp
>     cfe/trunk/lib/Sema/TreeTransform.h
>     cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
>     cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
>     cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>     cfe/trunk/test/OpenMP/nesting_of_regions.cpp
>     cfe/trunk/test/OpenMP/sections_ast_print.cpp
>     cfe/trunk/test/OpenMP/sections_misc_messages.c
>     cfe/trunk/tools/libclang/CIndex.cpp
>     cfe/trunk/tools/libclang/CXCursor.cpp
>
> Modified: cfe/trunk/include/clang-c/Index.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang-c/Index.h (original)
> +++ cfe/trunk/include/clang-c/Index.h Thu Jun 26 03:21:58 2014
> @@ -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.
>
> Modified: cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h (original)
> +++ cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h Thu Jun 26
> 03:21:58 2014
> @@ -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) {
>
> Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
> +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Thu Jun 26 03:21:58
> 2014
> @@ -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) {
>
> Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
> +++ cfe/trunk/include/clang/AST/StmtOpenMP.h Thu Jun 26 03:21:58 2014
> @@ -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
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun 26
> 03:21:58 2014
> @@ -7115,6 +7115,11 @@ def err_omp_prohibited_region_simd : Err
>    "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 {
>
> Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
> +++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jun 26 03:21:58 2014
> @@ -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)
>
> Modified: cfe/trunk/include/clang/Basic/StmtNodes.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/StmtNodes.td?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/StmtNodes.td (original)
> +++ cfe/trunk/include/clang/Basic/StmtNodes.td Thu Jun 26 03:21:58 2014
> @@ -181,3 +181,4 @@ def OMPParallelDirective : DStmt<OMPExec
>  def OMPSimdDirective : DStmt<OMPExecutableDirective>;
>  def OMPForDirective : DStmt<OMPExecutableDirective>;
>  def OMPSectionsDirective : DStmt<OMPExecutableDirective>;
> +def OMPSectionDirective : DStmt<OMPExecutableDirective>;
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Thu Jun 26 03:21:58 2014
> @@ -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,
>
> Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Thu Jun 26
> 03:21:58 2014
> @@ -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
>
> Modified: cfe/trunk/lib/AST/Stmt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/Stmt.cpp (original)
> +++ cfe/trunk/lib/AST/Stmt.cpp Thu Jun 26 03:21:58 2014
> @@ -1410,3 +1410,23 @@ OMPSectionsDirective *OMPSectionsDirecti
>    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();
> +}
> +
>
> Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/StmtPrinter.cpp Thu Jun 26 03:21:58 2014
> @@ -792,6 +792,11 @@ void StmtPrinter::VisitOMPSectionsDirect
>    PrintOMPExecutableDirective(Node);
>  }
>
> +void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
> +  Indent() << "#pragma omp section";
> +  PrintOMPExecutableDirective(Node);
> +}
> +
>
>  //===----------------------------------------------------------------------===//
>  //  Expr printing methods.
>
>  //===----------------------------------------------------------------------===//
>
> Modified: cfe/trunk/lib/AST/StmtProfile.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/StmtProfile.cpp (original)
> +++ cfe/trunk/lib/AST/StmtProfile.cpp Thu Jun 26 03:21:58 2014
> @@ -364,6 +364,10 @@ void StmtProfiler::VisitOMPSectionsDirec
>    VisitOMPExecutableDirective(S);
>  }
>
> +void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S)
> {
> +  VisitOMPExecutableDirective(S);
> +}
> +
>  void StmtProfiler::VisitExpr(const Expr *S) {
>    VisitStmt(S);
>  }
>
> Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
> +++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Thu Jun 26 03:21:58 2014
> @@ -204,6 +204,7 @@ bool clang::isAllowedClauseForDirective(
>    case OMPD_unknown:
>    case OMPD_threadprivate:
>    case OMPD_task:
> +  case OMPD_section:
>      break;
>    }
>    return false;
> @@ -214,8 +215,8 @@ bool clang::isOpenMPLoopDirective(OpenMP
>  }
>
>  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) {
>
> Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Jun 26 03:21:58 2014
> @@ -185,6 +185,9 @@ void CodeGenFunction::EmitStmt(const Stm
>    case Stmt::OMPSectionsDirectiveClass:
>      EmitOMPSectionsDirective(cast<OMPSectionsDirective>(*S));
>      break;
> +  case Stmt::OMPSectionDirectiveClass:
> +    EmitOMPSectionDirective(cast<OMPSectionDirective>(*S));
> +    break;
>    }
>  }
>
>
> Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Thu Jun 26 03:21:58 2014
> @@ -83,3 +83,7 @@ void CodeGenFunction::EmitOMPSectionsDir
>    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.");
> +}
> +
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Jun 26 03:21:58 2014
> @@ -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
>
> Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Thu Jun 26 03:21:58 2014
> @@ -64,6 +64,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpen
>    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::ParseOpen
>  ///         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::ParseOpenMPDeclarativ
>    case OMPD_parallel:
>    case OMPD_simd:
>    case OMPD_for:
> -  case OMPD_sections: {
> +  case OMPD_sections:
> +  case OMPD_section: {
>      ConsumeToken();
>
>      if (isOpenMPLoopDirective(DKind))
>
> Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Jun 26 03:21:58 2014
> @@ -917,6 +917,13 @@ void Sema::ActOnOpenMPRegionStart(OpenMP
>      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
>        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::ActOnOpenMPExecutableDi
>      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::ActOnOpenMPSectionsDire
>        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::ActOnOpenMPSectionsDire
>                                        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,
>
> Modified: cfe/trunk/lib/Sema/TreeTransform.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jun 26 03:21:58 2014
> @@ -6439,6 +6439,16 @@ TreeTransform<Derived>::TransformOMPSect
>    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
>
>  //===----------------------------------------------------------------------===//
>
> Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Thu Jun 26 03:21:58 2014
> @@ -1913,6 +1913,11 @@ void ASTStmtReader::VisitOMPSectionsDire
>    VisitOMPExecutableDirective(D);
>  }
>
> +void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
> +  VisitStmt(D);
> +  VisitOMPExecutableDirective(D);
> +}
> +
>
>  //===----------------------------------------------------------------------===//
>  // ASTReader Implementation
>
>  //===----------------------------------------------------------------------===//
> @@ -2413,6 +2418,10 @@ Stmt *ASTReader::ReadStmtFromStream(Modu
>            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;
>
> Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Thu Jun 26 03:21:58 2014
> @@ -1825,6 +1825,12 @@ void ASTStmtWriter::VisitOMPSectionsDire
>    Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE;
>  }
>
> +void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
> +  VisitStmt(D);
> +  VisitOMPExecutableDirective(D);
> +  Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
> +}
> +
>
>  //===----------------------------------------------------------------------===//
>  // ASTWriter Implementation
>
>  //===----------------------------------------------------------------------===//
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Thu Jun 26 03:21:58
> 2014
> @@ -734,6 +734,7 @@ void ExprEngine::Visit(const Stmt *S, Ex
>      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:
>
> Modified: cfe/trunk/test/OpenMP/nesting_of_regions.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nesting_of_regions.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/OpenMP/nesting_of_regions.cpp (original)
> +++ cfe/trunk/test/OpenMP/nesting_of_regions.cpp Thu Jun 26 03:21:58 2014
> @@ -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>();
>  }
>
>
> Modified: cfe/trunk/test/OpenMP/sections_ast_print.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/sections_ast_print.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/OpenMP/sections_ast_print.cpp (original)
> +++ cfe/trunk/test/OpenMP/sections_ast_print.cpp Thu Jun 26 03:21:58 2014
> @@ -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]));
>
> Modified: cfe/trunk/test/OpenMP/sections_misc_messages.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/sections_misc_messages.c?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/OpenMP/sections_misc_messages.c (original)
> +++ cfe/trunk/test/OpenMP/sections_misc_messages.c Thu Jun 26 03:21:58 2014
> @@ -18,6 +18,13 @@ void test_no_clause() {
>  // expected-error at +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 at +1 {{unexpected OpenMP clause 'nowait' in directive
> '#pragma omp section'}}
> +#pragma omp section nowait
> +    ;
>    }
>  }
>
>
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Jun 26 03:21:58 2014
> @@ -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::VisitOMPSectionsDir
>    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(enu
>      return cxstring::createRef("OMPForDirective");
>    case CXCursor_OMPSectionsDirective:
>      return cxstring::createRef("OMPSectionsDirective");
> +  case CXCursor_OMPSectionDirective:
> +    return cxstring::createRef("OMPSectionDirective");
>    }
>
>    llvm_unreachable("Unhandled CXCursorKind");
>
> Modified: cfe/trunk/tools/libclang/CXCursor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=211767&r1=211766&r2=211767&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/libclang/CXCursor.cpp (original)
> +++ cfe/trunk/tools/libclang/CXCursor.cpp Thu Jun 26 03:21:58 2014
> @@ -525,6 +525,9 @@ CXCursor cxcursor::MakeCXCursor(const St
>    case Stmt::OMPSectionsDirectiveClass:
>      K = CXCursor_OMPSectionsDirective;
>      break;
> +  case Stmt::OMPSectionDirectiveClass:
> +    K = CXCursor_OMPSectionDirective;
> +    break;
>    }
>
>    CXCursor C = { K, 0, { Parent, S, TU } };
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140721/2dc31156/attachment.html>


More information about the cfe-commits mailing list