Why are we leaking a bunch of stuff here? If we're not using -disable-free, we should be cleaning up after ourselves.<br><br><div>On Wed Apr 23 2014 at 4:36:23 PM, Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">(pretend that resetAndLeakSema() is a one-liner saying "BuryPointer(TheSema.release())")</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 23, 2014 at 4:34 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Wed, Apr 23, 2014 at 3:46 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">


<div><div>On Wed, Apr 23, 2014 at 3:21 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Alexey,<div class="gmail_extra"><br></div>


<div class="gmail_extra">(below)<br><br><div class="gmail_quote">
<div>On Fri, Sep 6, 2013 at 11:03 AM, Alexey Bataev <span dir="ltr"><<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>></span> wrote:<br>

</div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: abataev<br>
Date: Fri Sep  6 13:03:48 2013<br>
New Revision: 190183<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=190183&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=190183&view=rev</a><br>
Log:<br>
OpenMP: Data-sharing attributes analysis and clause 'shared' (fixed test threadprivate_messages.cpp)<br>
<br>
Added:<br>
    cfe/trunk/test/OpenMP/parallel_messages.cpp   (with props)<br>
    cfe/trunk/test/OpenMP/parallel_shared_messages.cpp   (with props)<br>
Modified:<br>
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h<br>
    cfe/trunk/include/clang/AST/StmtOpenMP.h<br>
    cfe/trunk/include/clang/Basic/CapturedStmt.h<br>
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
    cfe/trunk/include/clang/Basic/OpenMPKinds.def<br>
    cfe/trunk/include/clang/Sema/Scope.h<br>
    cfe/trunk/include/clang/Sema/ScopeInfo.h<br>
    cfe/trunk/include/clang/Sema/Sema.h<br>
    cfe/trunk/lib/AST/Stmt.cpp<br>
    cfe/trunk/lib/AST/StmtPrinter.cpp<br>
    cfe/trunk/lib/AST/StmtProfile.cpp<br>
    cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
    cfe/trunk/lib/Parse/ParseOpenMP.cpp<br>
    cfe/trunk/lib/Sema/Sema.cpp<br>
    cfe/trunk/lib/Sema/SemaOpenMP.cpp<br>
    cfe/trunk/lib/Sema/TreeTransform.h<br>
    cfe/trunk/lib/Serialization/ASTReaderStmt.cpp<br>
    cfe/trunk/lib/Serialization/ASTWriterStmt.cpp<br>
    cfe/trunk/test/OpenMP/openmp_common.c<br>
    cfe/trunk/test/OpenMP/parallel_default_messages.cpp<br>
    cfe/trunk/test/OpenMP/parallel_private_messages.cpp<br>
    cfe/trunk/tools/libclang/CIndex.cpp<br>
    cfe/trunk/tools/libclang/RecursiveASTVisitor.h<br>
<br>
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)<br>
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Fri Sep  6 13:03:48 2013<br>
@@ -2346,12 +2346,17 @@ bool RecursiveASTVisitor<Derived>::Visit<br>
     TraverseStmt(*I);<br>
<br>
 template<typename Derived><br>
-bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(<br>
-                                                      OMPPrivateClause *C) {<br>
+bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {<br>
   PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)<br>
   return true;<br>
 }<br>
<br>
+template<typename Derived><br>
+bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {<br>
+  PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)<br>
+  return true;<br>
+}<br>
+<br>
 #undef PROCESS_OMP_CLAUSE_LIST<br>
<br>
 // FIXME: look at the following tricky-seeming exprs to see if we<br>
<br>
Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)<br>
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Fri Sep  6 13:03:48 2013<br>
@@ -249,6 +249,63 @@ public:<br>
   }<br>
 };<br>
<br>
+/// \brief This represents clause 'shared' in the '#pragma omp ...' directives.<br>
+///<br>
+/// \code<br>
+/// #pragma omp parallel shared(a,b)<br>
+/// \endcode<br>
+/// In this example directive '#pragma omp parallel' has clause 'shared'<br>
+/// with the variables 'a' and 'b'.<br>
+///<br>
+class OMPSharedClause : public OMPClause, public OMPVarList<OMPSharedClause> {<br>
+  /// \brief Build clause with number of variables \a N.<br>
+  ///<br>
+  /// \param StartLoc Starting location of the clause.<br>
+  /// \param LParenLoc Location of '('.<br>
+  /// \param EndLoc Ending location of the clause.<br>
+  /// \param N Number of the variables in the clause.<br>
+  ///<br>
+  OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,<br>
+                  SourceLocation EndLoc, unsigned N)<br>
+    : OMPClause(OMPC_shared, StartLoc, EndLoc),<br>
+      OMPVarList<OMPSharedClause>(LParenLoc, N) { }<br>
+<br>
+  /// \brief Build an empty clause.<br>
+  ///<br>
+  /// \param N Number of variables.<br>
+  ///<br>
+  explicit OMPSharedClause(unsigned N)<br>
+    : OMPClause(OMPC_private, SourceLocation(), SourceLocation()),<br>
+      OMPVarList<OMPSharedClause>(SourceLocation(), N) { }<br>
+public:<br>
+  /// \brief Creates clause with a list of variables \a VL.<br>
+  ///<br>
+  /// \param C AST context.<br>
+  /// \param StartLoc Starting location of the clause.<br>
+  /// \param LParenLoc Location of '('.<br>
+  /// \param EndLoc Ending location of the clause.<br>
+  /// \param VL List of references to the variables.<br>
+  ///<br>
+  static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,<br>
+                                 SourceLocation LParenLoc,<br>
+                                 SourceLocation EndLoc, ArrayRef<Expr *> VL);<br>
+  /// \brief Creates an empty clause with \a N variables.<br>
+  ///<br>
+  /// \param C AST context.<br>
+  /// \param N The number of variables.<br>
+  ///<br>
+  static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);<br>
+<br>
+  StmtRange children() {<br>
+    return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),<br>
+                     reinterpret_cast<Stmt **>(varlist_end()));<br>
+  }<br>
+<br>
+  static bool classof(const OMPClause *T) {<br>
+    return T->getClauseKind() == OMPC_shared;<br>
+  }<br>
+};<br>
+<br>
 //===----------------------------------------------------------------------===//<br>
 // AST classes for directives.<br>
 //===----------------------------------------------------------------------===//<br>
<br>
Modified: cfe/trunk/include/clang/Basic/CapturedStmt.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CapturedStmt.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CapturedStmt.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/Basic/CapturedStmt.h (original)<br>
+++ cfe/trunk/include/clang/Basic/CapturedStmt.h Fri Sep  6 13:03:48 2013<br>
@@ -15,7 +15,8 @@ namespace clang {<br>
<br>
 /// \brief The different kinds of captured statement.<br>
 enum CapturedRegionKind {<br>
-  CR_Default<br>
+  CR_Default,<br>
+  CR_OpenMP<br>
 };<br>
<br>
 } // end namespace clang<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep  6 13:03:48 2013<br>
@@ -6612,6 +6612,14 @@ def err_omp_clause_ref_type_arg : Error<<br>
   "arguments of OpenMP clause '%0' cannot be of reference type %1">;<br>
 def err_omp_threadprivate_incomplete_type : Error<<br>
   "threadprivate variable with incomplete type %0">;<br>
+def err_omp_no_dsa_for_variable : Error <<br>
+  "variable %0 must have explicitly specified data sharing attributes">;<br>
+def err_omp_wrong_dsa : Error<<br>
+  "%0 variable cannot be %1">;<br>
+def note_omp_explicit_dsa : Note <<br>
+  "defined as %0">;<br>
+def note_omp_predetermined_dsa : Note <<br>
+  "predetermined as %0">;<br>
 } // end of OpenMP category<br>
<br>
 let CategoryName = "Related Result Type Issue" in {<br>
<br>
Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)<br>
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Fri Sep  6 13:03:48 2013<br>
@@ -33,10 +33,12 @@ OPENMP_DIRECTIVE(task)<br>
 // OpenMP clauses.<br>
 OPENMP_CLAUSE(default, OMPDefaultClause)<br>
 OPENMP_CLAUSE(private, OMPPrivateClause)<br>
+OPENMP_CLAUSE(shared,  OMPSharedClause)<br>
<br>
 // Clauses allowed for OpenMP directives.<br>
 OPENMP_PARALLEL_CLAUSE(default)<br>
 OPENMP_PARALLEL_CLAUSE(private)<br>
+OPENMP_PARALLEL_CLAUSE(shared)<br>
<br>
 // Static attributes for 'default' clause.<br>
 OPENMP_DEFAULT_KIND(none)<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Scope.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Scope.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Scope.h Fri Sep  6 13:03:48 2013<br>
@@ -91,7 +91,10 @@ public:<br>
     TryScope = 0x2000,<br>
<br>
     /// \brief This is the scope for a function-level C++ try or catch scope.<br>
-    FnTryCatchScope = 0x4000<br>
+    FnTryCatchScope = 0x4000,<br>
+<br>
+    /// \brief This is the scope of OpenMP executable directive<br>
+    OpenMPDirectiveScope = 0x8000<br>
   };<br>
 private:<br>
   /// The parent scope for this scope.  This is null for the translation-unit<br>
@@ -301,7 +304,12 @@ public:<br>
     }<br>
     return false;<br>
   }<br>
-<br>
+<br>
+  /// \brief Determines whether this scope is the OpenMP directive scope<br>
+  bool isOpenMPDirectiveScope() const {<br>
+    return (getFlags() & Scope::OpenMPDirectiveScope);<br>
+  }<br>
+<br>
   /// \brief Determine whether this scope is a C++ 'try' block.<br>
   bool isTryScope() const { return getFlags() & Scope::TryScope; }<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)<br>
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Fri Sep  6 13:03:48 2013<br>
@@ -567,6 +567,8 @@ public:<br>
     switch (CapRegionKind) {<br>
     case CR_Default:<br>
       return "default captured statement";<br>
+    case CR_OpenMP:<br>
+      return "OpenMP region";<br>
     }<br>
     llvm_unreachable("Invalid captured region kind!");<br>
   }<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Sep  6 13:03:48 2013<br>
@@ -6887,6 +6887,20 @@ public:<br>
                       unsigned SpellingListIndex, bool IsPackExpansion);<br>
<br>
   // OpenMP directives and clauses.<br>
+private:<br>
+  void *VarDataSharingAttributesStack;<br>
+  /// \brief Initialization of data-sharing attributes stack.<br>
+  void InitDataSharingAttributesStack();<br>
+  void DestroyDataSharingAttributesStack();<br>
+public:<br>
+  /// \brief Called on start of new data sharing attribute block.<br>
+  void StartOpenMPDSABlock(OpenMPDirectiveKind K,<br>
+                           const DeclarationNameInfo &DirName,<br>
+                           Scope *CurScope);<br>
+  /// \brief Called on end of data sharing attribute block.<br>
+  void EndOpenMPDSABlock(Stmt *CurDirective);<br>
+<br>
+  // OpenMP directives and clauses.<br>
   /// \brief Called on correct id-expression from the '#pragma omp<br>
   /// threadprivate'.<br>
   ExprResult ActOnOpenMPIdExpression(Scope *CurScope,<br>
@@ -6936,6 +6950,11 @@ public:<br>
                                       SourceLocation StartLoc,<br>
                                       SourceLocation LParenLoc,<br>
                                       SourceLocation EndLoc);<br>
+  /// \brief Called on well-formed 'shared' clause.<br>
+  OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,<br>
+                                     SourceLocation StartLoc,<br>
+                                     SourceLocation LParenLoc,<br>
+                                     SourceLocation EndLoc);<br>
<br>
   /// \brief The kind of conversion being performed.<br>
   enum CheckedConversionKind {<br>
<br>
Modified: cfe/trunk/lib/AST/Stmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/AST/Stmt.cpp (original)<br>
+++ cfe/trunk/lib/AST/Stmt.cpp Fri Sep  6 13:03:48 2013<br>
@@ -1111,6 +1111,16 @@ bool CapturedStmt::capturesVariable(cons<br>
   return false;<br>
 }<br>
<br>
+StmtRange OMPClause::children() {<br>
+  switch(getClauseKind()) {<br>
+  default : break;<br>
+#define OPENMP_CLAUSE(Name, Class)                                       \<br>
+  case OMPC_ ## Name : return static_cast<Class *>(this)->children();<br>
+#include "clang/Basic/OpenMPKinds.def"<br>
+  }<br>
+  llvm_unreachable("unknown OMPClause");<br>
+}<br>
+<br>
 OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C,<br>
                                            SourceLocation StartLoc,<br>
                                            SourceLocation LParenLoc,<br>
@@ -1131,6 +1141,26 @@ OMPPrivateClause *OMPPrivateClause::Crea<br>
   return new (Mem) OMPPrivateClause(N);<br>
 }<br>
<br>
+OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,<br>
+                                         SourceLocation StartLoc,<br>
+                                         SourceLocation LParenLoc,<br>
+                                         SourceLocation EndLoc,<br>
+                                         ArrayRef<Expr *> VL) {<br>
+  void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * VL.size(),<br>
+                         llvm::alignOf<OMPSharedClause>());<br>
+  OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,<br>
+                                                      EndLoc, VL.size());<br>
+  Clause->setVarRefs(VL);<br>
+  return Clause;<br>
+}<br>
+<br>
+OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,<br>
+                                              unsigned N) {<br>
+  void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * N,<br>
+                         llvm::alignOf<OMPSharedClause>());<br>
+  return new (Mem) OMPSharedClause(N);<br>
+}<br>
+<br>
 void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {<br>
   assert(Clauses.size() == this->Clauses.size() &&<br>
          "Number of clauses is not the same as the preallocated buffer");<br>
<br>
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)<br>
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Sep  6 13:03:48 2013<br>
@@ -614,6 +614,14 @@ void OMPClausePrinter::VisitOMPPrivateCl<br>
   }<br>
 }<br>
<br>
+void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {<br>
+  if (!Node->varlist_empty()) {<br>
+    OS << "shared";<br>
+    PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, Node, '(')<br>
+    OS << ")";<br>
+  }<br>
+}<br>
+<br>
 #undef PROCESS_OMP_CLAUSE_LIST<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/AST/StmtProfile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)<br>
+++ cfe/trunk/lib/AST/StmtProfile.cpp Fri Sep  6 13:03:48 2013<br>
@@ -272,6 +272,9 @@ void OMPClauseProfiler::VisitOMPDefaultC<br>
 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {<br>
   PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)<br>
 }<br>
+void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {<br>
+  PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)<br>
+}<br>
 #undef PROCESS_OMP_CLAUSE_LIST<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Sep  6 13:03:48 2013<br>
@@ -136,8 +136,10 @@ void CodeGenFunction::EmitStmt(const Stm<br>
   case Stmt::SwitchStmtClass:   EmitSwitchStmt(cast<SwitchStmt>(*S));     break;<br>
   case Stmt::GCCAsmStmtClass:   // Intentional fall-through.<br>
   case Stmt::MSAsmStmtClass:    EmitAsmStmt(cast<AsmStmt>(*S));           break;<br>
-  case Stmt::CapturedStmtClass:<br>
-    EmitCapturedStmt(cast<CapturedStmt>(*S), CR_Default);<br>
+  case Stmt::CapturedStmtClass: {<br>
+    const CapturedStmt *CS = cast<CapturedStmt>(S);<br>
+    EmitCapturedStmt(*CS, CS->getCapturedRegionKind());<br>
+    }<br>
     break;<br>
   case Stmt::ObjCAtTryStmtClass:<br>
     EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Fri Sep  6 13:03:48 2013<br>
@@ -84,11 +84,14 @@ StmtResult Parser::ParseOpenMPDeclarativ<br>
   SmallVector<OMPClause *, 5> Clauses;<br>
   SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, NUM_OPENMP_CLAUSES><br>
                                                FirstClauses(NUM_OPENMP_CLAUSES);<br>
-  const unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope;<br>
+  const unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |<br>
+                              Scope::OpenMPDirectiveScope;<br>
   SourceLocation Loc = ConsumeToken(), EndLoc;<br>
   OpenMPDirectiveKind DKind = Tok.isAnnotation() ?<br>
                                   OMPD_unknown :<br>
                                   getOpenMPDirectiveKind(PP.getSpelling(Tok));<br>
+  // Name of critical directive.<br>
+  DeclarationNameInfo DirName;<br>
   StmtResult Directive = StmtError();<br>
<br>
   switch (DKind) {<br>
@@ -111,6 +114,9 @@ StmtResult Parser::ParseOpenMPDeclarativ<br>
     break;<br>
   case OMPD_parallel: {<br>
     ConsumeToken();<br>
+<br>
+    Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope());<br>
+<br>
     while (Tok.isNot(tok::annot_pragma_openmp_end)) {<br>
       OpenMPClauseKind CKind = Tok.isAnnotation() ?<br>
                                   OMPC_unknown :<br>
@@ -138,7 +144,7 @@ StmtResult Parser::ParseOpenMPDeclarativ<br>
     {<br>
       // The body is a block scope like in Lambdas and Blocks.<br>
       Sema::CompoundScopeRAII CompoundScope(Actions);<br>
-      Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_Default, 1);<br>
+      Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_OpenMP, 1);<br>
       Actions.ActOnStartOfCompoundStmt();<br>
       // Parse statement<br>
       AssociatedStmt = ParseStatement();<br>
@@ -157,6 +163,7 @@ StmtResult Parser::ParseOpenMPDeclarativ<br>
                                                          Loc, EndLoc);<br>
<br>
     // Exit scope.<br>
+    Actions.EndOpenMPDSABlock(Directive.get());<br>
     OMPDirectiveScope.Exit();<br>
     }<br>
     break;<br>
@@ -245,7 +252,7 @@ bool Parser::ParseOpenMPSimpleVarList(Op<br>
 /// \brief Parsing of OpenMP clauses.<br>
 ///<br>
 ///    clause:<br>
-///       default-clause|private-clause<br>
+///       default-clause|private-clause|shared-clause<br>
 ///<br>
 OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,<br>
                                      OpenMPClauseKind CKind, bool FirstClause) {<br>
@@ -271,6 +278,7 @@ OMPClause *Parser::ParseOpenMPClause(Ope<br>
     Clause = ParseOpenMPSimpleClause(CKind);<br>
     break;<br>
   case OMPC_private:<br>
+  case OMPC_shared:<br>
     Clause = ParseOpenMPVarListClause(CKind);<br>
     break;<br>
   case OMPC_unknown:<br>
@@ -322,6 +330,8 @@ OMPClause *Parser::ParseOpenMPSimpleClau<br>
 ///<br>
 ///    private-clause:<br>
 ///       'private' '(' list ')'<br>
+///    shared-clause:<br>
+///       'shared' '(' list ')'<br>
 ///<br>
 OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {<br>
   SourceLocation Loc = Tok.getLocation();<br>
<br>
Modified: cfe/trunk/lib/Sema/Sema.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/Sema/Sema.cpp (original)<br>
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Sep  6 13:03:48 2013<br>
@@ -90,7 +90,8 @@ Sema::Sema(Preprocessor &pp, ASTContext<br>
     AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),<br>
     NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),<br>
     CurrentInstantiationScope(0), TyposCorrected(0),<br>
-    AnalysisWarnings(*this), CurScope(0), Ident_super(0), Ident___float128(0)<br>
+    AnalysisWarnings(*this), VarDataSharingAttributesStack(0), CurScope(0),<br>
+    Ident_super(0), Ident___float128(0)<br>
 {<br>
   TUScope = 0;<br>
<br>
@@ -113,6 +114,9 @@ Sema::Sema(Preprocessor &pp, ASTContext<br>
                                           false, 0, false));<br>
<br>
   FunctionScopes.push_back(new FunctionScopeInfo(Diags));<br>
+<br>
+  // Initilization of data sharing attributes stack for OpenMP<br>
+  InitDataSharingAttributesStack();<br>
 }<br>
<br>
 void Sema::Initialize() {<br>
@@ -199,6 +203,9 @@ Sema::~Sema() {<br>
   // If Sema's ExternalSource is the multiplexer - we own it.<br>
   if (isMultiplexExternalSource)<br>
     delete ExternalSource;<br>
+<br>
+  // Destroys data sharing attributes stack for OpenMP<br>
+  DestroyDataSharingAttributesStack();<br>
 }<br>
<br>
 /// makeUnavailableInSystemHeader - There is an error in the current<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Sep  6 13:03:48 2013<br>
@@ -27,6 +27,325 @@<br>
 #include "clang/Sema/ScopeInfo.h"<br>
 using namespace clang;<br>
<br>
+//===----------------------------------------------------------------------===//<br>
+// Stack of data-sharing attributes for variables<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+namespace {<br>
+/// \brief Default data sharing attributes, which can be applied to directive.<br>
+enum DefaultDataSharingAttributes {<br>
+  DSA_unspecified = 0,   /// \brief Data sharing attribute not specified.<br>
+  DSA_none = 1 << 0,     /// \brief Default data sharing attribute 'none'.<br>
+  DSA_shared = 1 << 1    /// \brief Default data sharing attribute 'shared'.<br>
+};<br>
+<br>
+/// \brief Stack for tracking declarations used in OpenMP directives and<br>
+/// clauses and their data-sharing attributes.<br>
+class DSAStackTy {<br>
+public:<br>
+  struct DSAVarData {<br>
+    OpenMPDirectiveKind DKind;<br>
+    OpenMPClauseKind CKind;<br>
+    DeclRefExpr *RefExpr;<br>
+    DSAVarData() : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(0) { }<br>
+  };<br>
+private:<br>
+  struct DSAInfo {<br>
+    OpenMPClauseKind Attributes;<br>
+    DeclRefExpr *RefExpr;<br>
+  };<br>
+  typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy;<br>
+<br>
+  struct SharingMapTy {<br>
+    DeclSAMapTy SharingMap;<br>
+    DefaultDataSharingAttributes DefaultAttr;<br>
+    OpenMPDirectiveKind Directive;<br>
+    DeclarationNameInfo DirectiveName;<br>
+    Scope *CurScope;<br>
+    SharingMapTy(OpenMPDirectiveKind DKind,<br>
+                 const DeclarationNameInfo &Name,<br>
+                 Scope *CurScope)<br>
+      : SharingMap(), DefaultAttr(DSA_unspecified), Directive(DKind),<br>
+        DirectiveName(Name), CurScope(CurScope) { }<br>
+    SharingMapTy()<br>
+      : SharingMap(), DefaultAttr(DSA_unspecified),<br>
+        Directive(OMPD_unknown), DirectiveName(),<br>
+        CurScope(0) { }<br>
+  };<br>
+<br>
+  typedef SmallVector<SharingMapTy, 64> StackTy;<br>
+<br>
+  /// \brief Stack of used declaration and their data-sharing attributes.<br>
+  StackTy Stack;<br>
+  Sema &Actions;<br>
+<br>
+  typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator;<br>
+<br>
+  DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D);<br>
+public:<br>
+  explicit DSAStackTy(Sema &S) : Stack(1), Actions(S) { }<br>
+<br>
+  void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName,<br>
+            Scope *CurScope) {<br>
+    Stack.push_back(SharingMapTy(DKind, DirName, CurScope));<br>
+  }<br>
+<br>
+  void pop() {<br>
+    assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!");<br>
+    Stack.pop_back();<br>
+  }<br>
+<br>
+  /// \brief Adds explicit data sharing attribute to the specified declaration.<br>
+  void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A);<br>
+<br>
+  /// \brief Checks if the variable is a local for OpenMP region.<br>
+  bool isOpenMPLocal(VarDecl *D);<br>
+<br>
+  /// \brief Returns data sharing attributes from top of the stack for the<br>
+  /// specified declaration.<br>
+  DSAVarData getTopDSA(VarDecl *D);<br>
+  /// \brief Returns data-sharing attributes for the specified declaration.<br>
+  DSAVarData getImplicitDSA(VarDecl *D);<br>
+<br>
+  /// \brief Returns currently analyzed directive.<br>
+  OpenMPDirectiveKind getCurrentDirective() const {<br>
+    return Stack.back().Directive;<br>
+  }<br>
+<br>
+  /// \brief Set default data sharing attribute to none.<br>
+  void setDefaultDSANone() { Stack.back().DefaultAttr = DSA_none; }<br>
+  /// \brief Set default data sharing attribute to shared.<br>
+  void setDefaultDSAShared() { Stack.back().DefaultAttr = DSA_shared; }<br>
+<br>
+  DefaultDataSharingAttributes getDefaultDSA() const {<br>
+    return Stack.back().DefaultAttr;<br>
+  }<br>
+<br>
+  Scope *getCurScope() { return Stack.back().CurScope; }<br>
+};<br>
+} // end anonymous namespace.<br>
+<br>
+DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,<br>
+                                          VarDecl *D) {<br>
+  DSAVarData DVar;<br>
+  if (Iter == Stack.rend() - 1) {<br>
+    // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+    // in a region but not in construct]<br>
+    //  File-scope or namespace-scope variables referenced in called routines<br>
+    //  in the region are shared unless they appear in a threadprivate<br>
+    //  directive.<br>
+    // TODO<br>
+    if (!D->isFunctionOrMethodVarDecl())<br>
+      DVar.CKind = OMPC_shared;<br>
+<br>
+    return DVar;<br>
+  }<br>
+  DVar.DKind = Iter->Directive;<br>
+  // Explicitly specified attributes and local variables with predetermined<br>
+  // attributes.<br>
+  if (Iter->SharingMap.count(D)) {<br>
+    DVar.RefExpr = Iter->SharingMap[D].RefExpr;<br>
+    DVar.CKind = Iter->SharingMap[D].Attributes;<br>
+    return DVar;<br>
+  }<br>
+<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, C/C++, implicitly determined, p.1]<br>
+  //  In a parallel or task construct, the data-sharing attributes of these<br>
+  //  variables are determined by the default clause, if present.<br>
+  switch (Iter->DefaultAttr) {<br>
+  case DSA_shared:<br>
+    DVar.CKind = OMPC_shared;<br>
+    return DVar;<br>
+  case DSA_none:<br>
+    return DVar;<br>
+  case DSA_unspecified:<br>
+    // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+    // in a Construct, implicitly determined, p.2]<br>
+    //  In a parallel construct, if no default clause is present, these<br>
+    //  variables are shared.<br>
+    if (DVar.DKind == OMPD_parallel) {<br>
+      DVar.CKind = OMPC_shared;<br>
+      return DVar;<br>
+    }<br>
+<br>
+    // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+    // in a Construct, implicitly determined, p.4]<br>
+    //  In a task construct, if no default clause is present, a variable that in<br>
+    //  the enclosing context is determined to be shared by all implicit tasks<br>
+    //  bound to the current team is shared.<br>
+    // TODO<br>
+    if (DVar.DKind == OMPD_task) {<br>
+      DSAVarData DVarTemp;<br>
+      for (StackTy::reverse_iterator I = Iter + 1,<br>
+                                     EE = Stack.rend() - 1;<br>
+           I != EE; ++I) {<br>
+        // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+        // in a Construct, implicitly determined, p.6]<br>
+        //  In a task construct, if no default clause is present, a variable<br>
+        //  whose data-sharing attribute is not determined by the rules above is<br>
+        //  firstprivate.<br>
+        DVarTemp = getDSA(I, D);<br>
+        if (DVarTemp.CKind != OMPC_shared) {<br>
+          DVar.RefExpr = 0;<br>
+          DVar.DKind = OMPD_task;<br>
+          DVar.CKind = OMPC_unknown;<br>
+          // TODO: should return OMPC_firstprivate<br>
+          return DVar;<br>
+        }<br>
+        if (I->Directive == OMPD_parallel) break;<br>
+      }<br>
+      DVar.DKind = OMPD_task;<br>
+      // TODO: Should return OMPC_firstprivate instead of OMPC_unknown.<br>
+      DVar.CKind =<br>
+        (DVarTemp.CKind == OMPC_unknown) ? OMPC_unknown : OMPC_shared;<br>
+      return DVar;<br>
+    }<br>
+  }<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, implicitly determined, p.3]<br>
+  //  For constructs other than task, if no default clause is present, these<br>
+  //  variables inherit their data-sharing attributes from the enclosing<br>
+  //  context.<br>
+  return getDSA(Iter + 1, D);<br>
+}<br>
+<br>
+void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) {<br>
+  if (A == OMPC_threadprivate) {<br>
+    Stack[0].SharingMap[D].Attributes = A;<br>
+    Stack[0].SharingMap[D].RefExpr = E;<br>
+  } else {<br>
+    assert(Stack.size() > 1 && "Data-sharing attributes stack is empty");<br>
+    Stack.back().SharingMap[D].Attributes = A;<br>
+    Stack.back().SharingMap[D].RefExpr = E;<br>
+  }<br>
+}<br>
+<br>
+bool DSAStackTy::isOpenMPLocal(VarDecl *D) {<br>
+  Scope *CurScope = getCurScope();<br>
+  while (CurScope && !CurScope->isDeclScope(D))<br>
+    CurScope = CurScope->getParent();<br>
+  while (CurScope && !CurScope->isOpenMPDirectiveScope())<br>
+    CurScope = CurScope->getParent();<br>
+  bool isOpenMPLocal = !!CurScope;<br>
+  if (!isOpenMPLocal) {<br>
+    CurScope = getCurScope();<br>
+    while (CurScope && !CurScope->isOpenMPDirectiveScope())<br>
+      CurScope = CurScope->getParent();<br>
+    isOpenMPLocal =<br>
+      CurScope &&<br>
+      isa<CapturedDecl>(D->getDeclContext()) &&<br>
+      static_cast<DeclContext *>(<br>
+        CurScope->getFnParent()->getEntity())->Encloses(D->getDeclContext());<br>
+  }<br>
+  return isOpenMPLocal;<br>
+}<br>
+<br>
+DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) {<br>
+  DSAVarData DVar;<br>
+<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, C/C++, predetermined, p.1]<br>
+  //  Variables appearing in threadprivate directives are threadprivate.<br>
+  if (D->getTLSKind() != VarDecl::TLS_None) {<br>
+    DVar.CKind = OMPC_threadprivate;<br>
+    return DVar;<br>
+  }<br>
+  if (Stack[0].SharingMap.count(D)) {<br>
+    DVar.RefExpr = Stack[0].SharingMap[D].RefExpr;<br>
+    DVar.CKind = OMPC_threadprivate;<br>
+    return DVar;<br>
+  }<br>
+<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, C/C++, predetermined, p.1]<br>
+  // Variables with automatic storage duration that are declared in a scope<br>
+  // inside the construct are private.<br>
+  if (isOpenMPLocal(D) && D->isLocalVarDecl() &&<br>
+      (D->getStorageClass() == SC_Auto ||<br>
+       D->getStorageClass() == SC_None)) {<br>
+    DVar.CKind = OMPC_private;<br>
+    return DVar;<br>
+  }<br>
+<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, C/C++, predetermined, p.4]<br>
+  //  Static data memebers are shared.<br>
+  if (D->isStaticDataMember()) {<br>
+    // Variables with const-qualified type having no mutable member may be<br>
+    // listed in a firstprivate clause, even if they are static data members.<br>
+    // TODO:<br>
+    DVar.CKind = OMPC_shared;<br>
+    return DVar;<br>
+  }<br>
+<br>
+  QualType Type = D->getType().getNonReferenceType().getCanonicalType();<br>
+  bool IsConstant = Type.isConstant(Actions.getASTContext());<br>
+  while (Type->isArrayType()) {<br>
+    QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType();<br>
+    Type = ElemType.getNonReferenceType().getCanonicalType();<br>
+  }<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, C/C++, predetermined, p.6]<br>
+  //  Variables with const qualified type having no mutable member are<br>
+  //  shared.<br>
+  CXXRecordDecl *RD = Actions.getLangOpts().CPlusPlus ?<br>
+                                Type->getAsCXXRecordDecl() : 0;<br>
+  if (IsConstant &&<br>
+      !(Actions.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) {<br>
+    // Variables with const-qualified type having no mutable member may be<br>
+    // listed in a firstprivate clause, even if they are static data members.<br>
+    // TODO<br>
+    DVar.CKind = OMPC_shared;<br>
+    return DVar;<br>
+  }<br>
+<br>
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+  // in a Construct, C/C++, predetermined, p.7]<br>
+  //  Variables with static storage duration that are declared in a scope<br>
+  //  inside the construct are shared.<br>
+  if (isOpenMPLocal(D) && D->isStaticLocal()) {<br>
+    DVar.CKind = OMPC_shared;<br>
+    return DVar;<br>
+  }<br>
+<br>
+  // Explicitly specified attributes and local variables with predetermined<br>
+  // attributes.<br>
+  if (Stack.back().SharingMap.count(D)) {<br>
+    DVar.RefExpr = Stack.back().SharingMap[D].RefExpr;<br>
+    DVar.CKind = Stack.back().SharingMap[D].Attributes;<br>
+  }<br>
+<br>
+  return DVar;<br>
+}<br>
+<br>
+DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D) {<br>
+  return getDSA(Stack.rbegin() + 1, D);<br>
+}<br>
+<br>
+void Sema::InitDataSharingAttributesStack() {<br>
+  VarDataSharingAttributesStack = new DSAStackTy(*this);<br></blockquote><div><br></div></div></div><div>This is leaked, is that intentional?</div></div></div></div></blockquote><div><br></div></div></div><div>It's not leaked. The LSan failure that my magic 8-ball says you're looking at stems from not deleting Sema.</div>


</div></div></div></blockquote><div><br></div></div></div><div>Oh, you're right! The "define DSAStack" below confused my grepping.</div><div><br></div><div>I think what's happening then is that the Sema object isn't Bury()d in the isCurrentFileAST() case. The attached patch fixes this. Does that look ok?</div>

<div><div>
<div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">


<div><div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">


<div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



+}<br>
+<br>
+#define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack)<br>
+<br>
+void Sema::DestroyDataSharingAttributesStack() {<br>
+  delete DSAStack;<br>
+}<br>
+<br>
+void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind,<br>
+                               const DeclarationNameInfo &DirName,<br>
+                               Scope *CurScope) {<br>
+  DSAStack->push(DKind, DirName, CurScope);<br>
+  PushExpressionEvaluationContext(PotentiallyEvaluated);<br>
+}<br>
+<br>
+void Sema::EndOpenMPDSABlock(Stmt *CurDirective) {<br>
+  DSAStack->pop();<br>
+  DiscardCleanupsInEvaluationContext();<br>
+  PopExpressionEvaluationContext();<br>
+}<br>
+<br>
 namespace {<br>
<br>
 class VarDeclFilterCCC : public CorrectionCandidateCallback {<br>
@@ -130,6 +449,7 @@ ExprResult Sema::ActOnOpenMPIdExpression<br>
<br>
   QualType ExprType = VD->getType().getNonReferenceType();<br>
   ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_RValue, Id.getLoc());<br>
+  DSAStack->addDSA(VD, cast<DeclRefExpr>(DE.get()), OMPC_threadprivate);<br>
   return DE;<br>
 }<br>
<br>
@@ -192,12 +512,93 @@ OMPThreadPrivateDecl *Sema::CheckOMPThre<br>
                                                Loc, Vars);<br>
 }<br>
<br>
+namespace {<br>
+class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> {<br>
+  DSAStackTy *Stack;<br>
+  Sema &Actions;<br>
+  bool ErrorFound;<br>
+  CapturedStmt *CS;<br>
+public:<br>
+  void VisitDeclRefExpr(DeclRefExpr *E) {<br>
+    if(VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {<br>
+      if (VD->isImplicit() && VD->hasAttr<UnusedAttr>()) return;<br>
+      // Skip internally declared variables.<br>
+      if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) return;<br>
+<br>
+      SourceLocation ELoc = E->getExprLoc();<br>
+<br>
+      OpenMPDirectiveKind DKind = Stack->getCurrentDirective();<br>
+      DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD);<br>
+      if (DVar.CKind != OMPC_unknown) {<br>
+        if (DKind == OMPD_task && DVar.CKind != OMPC_shared &&<br>
+            DVar.CKind != OMPC_threadprivate && !DVar.RefExpr)<br>
+          // TODO: should be marked as firstprivate.<br>
+          ;<br>
+        return;<br>
+      }<br>
+      // The default(none) clause requires that each variable that is referenced<br>
+      // in the construct, and does not have a predetermined data-sharing<br>
+      // attribute, must have its data-sharing attribute explicitly determined<br>
+      // by being listed in a data-sharing attribute clause.<br>
+      if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none &&<br>
+          (DKind == OMPD_parallel || DKind == OMPD_task)) {<br>
+        ErrorFound = true;<br>
+        Actions.Diag(ELoc, diag::err_omp_no_dsa_for_variable) << VD;<br>
+        return;<br>
+      }<br>
+<br>
+      // OpenMP [2.9.3.6, Restrictions, p.2]<br>
+      //  A list item that appears in a reduction clause of the innermost<br>
+      //  enclosing worksharing or parallel construct may not be accessed in an<br>
+      //  explicit task.<br>
+      // TODO:<br>
+<br>
+      // Define implicit data-sharing attributes for task.<br>
+      DVar = Stack->getImplicitDSA(VD);<br>
+      if (DKind == OMPD_task && DVar.CKind != OMPC_shared) {<br>
+        // TODO: should be marked as firstprivate.<br>
+      }<br>
+    }<br>
+  }<br>
+  void VisitOMPExecutableDirective(OMPExecutableDirective *S) {<br>
+    for (ArrayRef<OMPClause *>::iterator I = S->clauses().begin(),<br>
+                                         E = S->clauses().end();<br>
+         I != E; ++I)<br>
+      if (OMPClause *C = *I)<br>
+        for (StmtRange R = C->children(); R; ++R)<br>
+          if (Stmt *Child = *R)<br>
+            Visit(Child);<br>
+  }<br>
+  void VisitStmt(Stmt *S) {<br>
+    for (Stmt::child_iterator I = S->child_begin(), E = S->child_end();<br>
+         I != E; ++I)<br>
+      if (Stmt *Child = *I)<br>
+        if (!isa<OMPExecutableDirective>(Child))<br>
+          Visit(Child);<br>
+    }<br>
+<br>
+  bool isErrorFound() { return ErrorFound; }<br>
+<br>
+  DSAAttrChecker(DSAStackTy *S, Sema &Actions, CapturedStmt *CS)<br>
+    : Stack(S), Actions(Actions), ErrorFound(false), CS(CS) { }<br>
+};<br>
+}<br>
+<br>
 StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,<br>
                                                 ArrayRef<OMPClause *> Clauses,<br>
                                                 Stmt *AStmt,<br>
                                                 SourceLocation StartLoc,<br>
                                                 SourceLocation EndLoc) {<br>
+  assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");<br>
+<br>
   StmtResult Res = StmtError();<br>
+<br>
+  // Check default data sharing attributes for referenced variables.<br>
+  DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt));<br>
+  DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt());<br>
+  if (DSAChecker.isErrorFound())<br>
+    return StmtError();<br>
+<br>
   switch (Kind) {<br>
   case OMPD_parallel:<br>
     Res = ActOnOpenMPParallelDirective(Clauses, AStmt, StartLoc, EndLoc);<br>
@@ -231,11 +632,12 @@ OMPClause *Sema::ActOnOpenMPSimpleClause<br>
   OMPClause *Res = 0;<br>
   switch (Kind) {<br>
   case OMPC_default:<br>
-    Res = ActOnOpenMPDefaultClause(<br>
-                             static_cast<OpenMPDefaultClauseKind>(Argument),<br>
-                             ArgumentLoc, StartLoc, LParenLoc, EndLoc);<br>
+    Res =<br>
+      ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument),<br>
+                               ArgumentLoc, StartLoc, LParenLoc, EndLoc);<br>
     break;<br>
   case OMPC_private:<br>
+  case OMPC_shared:<br>
   case OMPC_threadprivate:<br>
   case OMPC_unknown:<br>
   case NUM_OPENMP_CLAUSES:<br>
@@ -272,6 +674,16 @@ OMPClause *Sema::ActOnOpenMPDefaultClaus<br>
       << Values << getOpenMPClauseName(OMPC_default);<br>
     return 0;<br>
   }<br>
+  switch (Kind) {<br>
+  case OMPC_DEFAULT_none:<br>
+    DSAStack->setDefaultDSANone();<br>
+    break;<br>
+  case OMPC_DEFAULT_shared:<br>
+    DSAStack->setDefaultDSAShared();<br>
+    break;<br>
+  default:<br>
+    break;<br>
+  }<br>
   return new (Context) OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc,<br>
                                         EndLoc);<br>
 }<br>
@@ -286,6 +698,9 @@ OMPClause *Sema::ActOnOpenMPVarListClaus<br>
   case OMPC_private:<br>
     Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc);<br>
     break;<br>
+  case OMPC_shared:<br>
+    Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc);<br>
+    break;<br>
   case OMPC_default:<br>
   case OMPC_threadprivate:<br>
   case OMPC_unknown:<br>
@@ -396,6 +811,29 @@ OMPClause *Sema::ActOnOpenMPPrivateClaus<br>
       }<br>
     }<br>
<br>
+    // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+    // in a Construct]<br>
+    //  Variables with the predetermined data-sharing attributes may not be<br>
+    //  listed in data-sharing attributes clauses, except for the cases<br>
+    //  listed below. For these exceptions only, listing a predetermined<br>
+    //  variable in a data-sharing attribute clause is allowed and overrides<br>
+    //  the variable's predetermined data-sharing attributes.<br>
+    DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);<br>
+    if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) {<br>
+      Diag(ELoc, diag::err_omp_wrong_dsa)<br>
+         << getOpenMPClauseName(DVar.CKind)<br>
+         << getOpenMPClauseName(OMPC_private);<br>
+      if (DVar.RefExpr) {<br>
+        Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)<br>
+             << getOpenMPClauseName(DVar.CKind);<br>
+      } else {<br>
+        Diag(VD->getLocation(), diag::note_omp_predetermined_dsa)<br>
+             << getOpenMPClauseName(DVar.CKind);<br>
+      }<br>
+      continue;<br>
+    }<br>
+<br>
+    DSAStack->addDSA(VD, DE, OMPC_private);<br>
     Vars.push_back(DE);<br>
   }<br>
<br>
@@ -404,3 +842,65 @@ OMPClause *Sema::ActOnOpenMPPrivateClaus<br>
   return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);<br>
 }<br>
<br>
+OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,<br>
+                                         SourceLocation StartLoc,<br>
+                                         SourceLocation LParenLoc,<br>
+                                         SourceLocation EndLoc) {<br>
+  SmallVector<Expr *, 8> Vars;<br>
+  for (ArrayRef<Expr *>::iterator I = VarList.begin(), E = VarList.end();<br>
+       I != E; ++I) {<br>
+    if (*I && isa<DependentScopeDeclRefExpr>(*I)) {<br>
+      // It will be analyzed later.<br>
+      Vars.push_back(*I);<br>
+      continue;<br>
+    }<br>
+<br>
+    SourceLocation ELoc = (*I)->getExprLoc();<br>
+    // OpenMP [2.1, C/C++]<br>
+    //  A list item is a variable name.<br>
+    // OpenMP  [2.9.3.4, Restrictions, p.1]<br>
+    //  A variable that is part of another variable (as an array or<br>
+    //  structure element) cannot appear in a private clause.<br>
+    DeclRefExpr *DE = dyn_cast<DeclRefExpr>(*I);<br>
+    if (!DE || !isa<VarDecl>(DE->getDecl())) {<br>
+      Diag(ELoc, diag::err_omp_expected_var_name)<br>
+        << (*I)->getSourceRange();<br>
+      continue;<br>
+    }<br>
+    Decl *D = DE->getDecl();<br>
+    VarDecl *VD = cast<VarDecl>(D);<br>
+<br>
+    QualType Type = VD->getType();<br>
+    if (Type->isDependentType() || Type->isInstantiationDependentType()) {<br>
+      // It will be analyzed later.<br>
+      Vars.push_back(DE);<br>
+      continue;<br>
+    }<br>
+<br>
+    // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced<br>
+    // in a Construct]<br>
+    //  Variables with the predetermined data-sharing attributes may not be<br>
+    //  listed in data-sharing attributes clauses, except for the cases<br>
+    //  listed below. For these exceptions only, listing a predetermined<br>
+    //  variable in a data-sharing attribute clause is allowed and overrides<br>
+    //  the variable's predetermined data-sharing attributes.<br>
+    DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);<br>
+    if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && DVar.RefExpr) {<br>
+      Diag(ELoc, diag::err_omp_wrong_dsa)<br>
+         << getOpenMPClauseName(DVar.CKind)<br>
+         << getOpenMPClauseName(OMPC_shared);<br>
+      Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)<br>
+           << getOpenMPClauseName(DVar.CKind);<br>
+      continue;<br>
+    }<br>
+<br>
+    DSAStack->addDSA(VD, DE, OMPC_shared);<br>
+    Vars.push_back(DE);<br>
+  }<br>
+<br>
+  if (Vars.empty()) return 0;<br>
+<br>
+  return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);<br>
+}<br>
+<br>
+#undef DSAStack<br>
<br>
Modified: cfe/trunk/lib/Sema/TreeTransform.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/Sema/TreeTransform.h (original)<br>
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Sep  6 13:03:48 2013<br>
@@ -1312,6 +1312,14 @@ public:<br>
                                               EndLoc);<br>
   }<br>
<br>
+  OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,<br>
+                                    SourceLocation StartLoc,<br>
+                                    SourceLocation LParenLoc,<br>
+                                    SourceLocation EndLoc) {<br>
+    return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,<br>
+                                             EndLoc);<br>
+  }<br>
+<br>
   /// \brief Rebuild the operand to an Objective-C \@synchronized statement.<br>
   ///<br>
   /// By default, performs semantic analysis to build the new statement.<br>
@@ -6254,33 +6262,44 @@ TreeTransform<Derived>::TransformSEHHand<br>
 template<typename Derived><br>
 StmtResult<br>
 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {<br>
+  DeclarationNameInfo DirName;<br>
+  getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);<br>
+<br>
   // Transform the clauses<br>
-  SmallVector<OMPClause *, 5> TClauses;<br>
+  llvm::SmallVector<OMPClause *, 16> TClauses;<br>
   ArrayRef<OMPClause *> Clauses = D->clauses();<br>
   TClauses.reserve(Clauses.size());<br>
   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();<br>
        I != E; ++I) {<br>
     if (*I) {<br>
       OMPClause *Clause = getDerived().TransformOMPClause(*I);<br>
-      if (!Clause)<br>
+      if (!Clause) {<br>
+        getSema().EndOpenMPDSABlock(0);<br>
         return StmtError();<br>
+      }<br>
       TClauses.push_back(Clause);<br>
     }<br>
     else {<br>
       TClauses.push_back(0);<br>
     }<br>
   }<br>
-  if (!D->getAssociatedStmt())<br>
+  if (!D->getAssociatedStmt()) {<br>
+    getSema().EndOpenMPDSABlock(0);<br>
     return StmtError();<br>
+  }<br>
   StmtResult AssociatedStmt =<br>
     getDerived().TransformStmt(D->getAssociatedStmt());<br>
-  if (AssociatedStmt.isInvalid())<br>
+  if (AssociatedStmt.isInvalid()) {<br>
+    getSema().EndOpenMPDSABlock(0);<br>
     return StmtError();<br>
+  }<br>
<br>
-  return getDerived().RebuildOMPParallelDirective(TClauses,<br>
-                                                  AssociatedStmt.take(),<br>
-                                                  D->getLocStart(),<br>
-                                                  D->getLocEnd());<br>
+  StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,<br>
+                                                            AssociatedStmt.take(),<br>
+                                                            D->getLocStart(),<br>
+                                                            D->getLocEnd());<br>
+  getSema().EndOpenMPDSABlock(Res.get());<br>
+  return Res;<br>
 }<br>
<br>
 template<typename Derived><br>
@@ -6296,7 +6315,7 @@ TreeTransform<Derived>::TransformOMPDefa<br>
 template<typename Derived><br>
 OMPClause *<br>
 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {<br>
-  SmallVector<Expr *, 5> Vars;<br>
+  llvm::SmallVector<Expr *, 16> Vars;<br>
   Vars.reserve(C->varlist_size());<br>
   for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),<br>
                                                       E = C->varlist_end();<br>
@@ -6312,6 +6331,25 @@ TreeTransform<Derived>::TransformOMPPriv<br>
                                               C->getLocEnd());<br>
 }<br>
<br>
+template<typename Derived><br>
+OMPClause *<br>
+TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {<br>
+  llvm::SmallVector<Expr *, 16> Vars;<br>
+  Vars.reserve(C->varlist_size());<br>
+  for (OMPVarList<OMPSharedClause>::varlist_iterator I = C->varlist_begin(),<br>
+                                                     E = C->varlist_end();<br>
+       I != E; ++I) {<br>
+    ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));<br>
+    if (EVar.isInvalid())<br>
+      return 0;<br>
+    Vars.push_back(EVar.take());<br>
+  }<br>
+  return getDerived().RebuildOMPSharedClause(Vars,<br>
+                                             C->getLocStart(),<br>
+                                             C->getLParenLoc(),<br>
+                                             C->getLocEnd());<br>
+}<br>
+<br>
 //===----------------------------------------------------------------------===//<br>
 // Expression transformation<br>
 //===----------------------------------------------------------------------===//<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Fri Sep  6 13:03:48 2013<br>
@@ -1689,6 +1689,9 @@ OMPClause *OMPClauseReader::readClause()<br>
   case OMPC_private:<br>
     C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);<br>
     break;<br>
+  case OMPC_shared:<br>
+    C = OMPSharedClause::CreateEmpty(Context, Record[Idx++]);<br>
+    break;<br>
   }<br>
   Visit(C);<br>
   C->setLocStart(Reader->ReadSourceLocation(Record, Idx));<br>
@@ -1708,6 +1711,16 @@ void OMPClauseReader::VisitOMPPrivateCla<br>
   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));<br>
   unsigned NumVars = C->varlist_size();<br>
   SmallVector<Expr *, 16> Vars;<br>
+  Vars.reserve(NumVars);<br>
+  for (unsigned i = 0; i != NumVars; ++i)<br>
+    Vars.push_back(Reader->Reader.ReadSubExpr());<br>
+  C->setVarRefs(Vars);<br>
+}<br>
+<br>
+void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {<br>
+  C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));<br>
+  unsigned NumVars = C->varlist_size();<br>
+  SmallVector<Expr *, 16> Vars;<br>
   Vars.reserve(NumVars);<br>
   for (unsigned i = 0; i != NumVars; ++i)<br>
     Vars.push_back(Reader->Reader.ReadSubExpr());<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Fri Sep  6 13:03:48 2013<br>
@@ -1703,6 +1703,15 @@ void OMPClauseWriter::VisitOMPPrivateCla<br>
     Writer->Writer.AddStmt(*I);<br>
 }<br>
<br>
+void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {<br>
+  Record.push_back(C->varlist_size());<br>
+  Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);<br>
+  for (OMPVarList<OMPSharedClause>::varlist_iterator I = C->varlist_begin(),<br>
+                                                     E = C->varlist_end();<br>
+       I != E; ++I)<br>
+    Writer->Writer.AddStmt(*I);<br>
+}<br>
+<br>
 //===----------------------------------------------------------------------===//<br>
 // OpenMP Directives.<br>
 //===----------------------------------------------------------------------===//<br>
<br>
Modified: cfe/trunk/test/OpenMP/openmp_common.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_common.c?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_common.c?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/test/OpenMP/openmp_common.c (original)<br>
+++ cfe/trunk/test/OpenMP/openmp_common.c Fri Sep  6 13:03:48 2013<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 -o - %s<br>
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s<br>
<br>
 #pragma omp // expected-error {{expected an OpenMP directive}}<br>
 #pragma omp unknown_directive // expected-error {{expected an OpenMP directive}}<br>
<br>
Modified: cfe/trunk/test/OpenMP/parallel_default_messages.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_default_messages.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_default_messages.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/test/OpenMP/parallel_default_messages.cpp (original)<br>
+++ cfe/trunk/test/OpenMP/parallel_default_messages.cpp Fri Sep  6 13:03:48 2013<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 -o - %s<br>
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s<br>
<br>
 void foo();<br>
<br>
@@ -11,5 +11,11 @@ int main(int argc, char **argv) {<br>
   #pragma omp parallel default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}<br>
   foo();<br>
<br>
+  #pragma omp parallel default(none)<br>
+  ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}<br>
+<br>
+  #pragma omp parallel default(none)<br>
+  #pragma omp parallel default(shared)<br>
+  ++argc;<br>
   return 0;<br>
 }<br>
<br>
Added: cfe/trunk/test/OpenMP/parallel_messages.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_messages.cpp?rev=190183&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_messages.cpp?rev=190183&view=auto</a><br>






==============================================================================<br>
--- cfe/trunk/test/OpenMP/parallel_messages.cpp (added)<br>
+++ cfe/trunk/test/OpenMP/parallel_messages.cpp Fri Sep  6 13:03:48 2013<br>
@@ -0,0 +1,49 @@<br>
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s<br>
+<br>
+void foo() {<br>
+}<br>
+<br>
+#pragma omp parallel // expected-error {{unexpected OpenMP directive '#pragma omp parallel'}}<br>
+<br>
+int main(int argc, char **argv) {<br>
+  #pragma omp parallel<br>
+  #pragma omp parallel unknown() // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}<br>
+  foo();<br>
+  L1:<br>
+    foo();<br>
+  #pragma omp parallel<br>
+  ;<br>
+  #pragma omp parallel<br>
+  {<br>
+    goto L1; // expected-error {{use of undeclared label 'L1'}}<br>
+    argc++;<br>
+  }<br>
+<br>
+  for (int i = 0; i < 10; ++i) {<br>
+    switch(argc) {<br>
+     case (0):<br>
+      #pragma omp parallel<br>
+      {<br>
+        foo();<br>
+        break; // expected-error {{'break' statement not in loop or switch statement}}<br>
+        continue; // expected-error {{'continue' statement not in loop statement}}<br>
+      }<br>
+      default:<br>
+       break;<br>
+    }<br>
+  }<br>
+  #pragma omp parallel default(none)<br>
+  ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}<br>
+<br>
+  goto L2; // expected-error {{use of undeclared label 'L2'}}<br>
+  #pragma omp parallel<br>
+  L2:<br>
+  foo();<br>
+  #pragma omp parallel<br>
+  {<br>
+    return 1; // expected-error {{cannot return from OpenMP region}}<br>
+  }<br>
+<br>
+  return 0;<br>
+}<br>
+<br>
<br>
Propchange: cfe/trunk/test/OpenMP/parallel_messages.cpp<br>
------------------------------------------------------------------------------<br>
    svn:eol-style = native<br>
<br>
Propchange: cfe/trunk/test/OpenMP/parallel_messages.cpp<br>
------------------------------------------------------------------------------<br>
    svn:keywords = Author Date Id Rev URL<br>
<br>
Propchange: cfe/trunk/test/OpenMP/parallel_messages.cpp<br>
------------------------------------------------------------------------------<br>
    svn:mime-type = text/plain<br>
<br>
Modified: cfe/trunk/test/OpenMP/parallel_private_messages.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_private_messages.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_private_messages.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/test/OpenMP/parallel_private_messages.cpp (original)<br>
+++ cfe/trunk/test/OpenMP/parallel_private_messages.cpp Fri Sep  6 13:03:48 2013<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 %s<br>
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s<br>
<br>
 void foo() {<br>
 }<br>
@@ -13,7 +13,7 @@ class S2 {<br>
   mutable int a;<br>
 public:<br>
   S2():a(0) { }<br>
-  static float S2s;<br>
+  static float S2s; // expected-note {{predetermined as shared}}<br>
 };<br>
 const S2 b;<br>
 const S2 ba[5];<br>
@@ -22,9 +22,9 @@ class S3 {<br>
 public:<br>
   S3():a(0) { }<br>
 };<br>
-const S3 c;<br>
-const S3 ca[5];<br>
-extern const int f;<br>
+const S3 c; // expected-note {{predetermined as shared}}<br>
+const S3 ca[5]; // expected-note {{predetermined as shared}}<br>
+extern const int f; // expected-note {{predetermined as shared}}<br>
 class S4 { // expected-note {{'S4' declared here}}<br>
   int a;<br>
   S4();<br>
@@ -38,9 +38,12 @@ public:<br>
   S5(int v):a(v) { }<br>
 };<br>
<br>
+int threadvar;<br>
+#pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}}<br>
+<br>
 int main(int argc, char **argv) {<br>
-  const int d = 5;<br>
-  const int da[5] = { 0 };<br>
+  const int d = 5; // expected-note {{predetermined as shared}}<br>
+  const int da[5] = { 0 }; // expected-note {{predetermined as shared}}<br>
   S4 e(4); // expected-note {{'e' defined here}}<br>
   S5 g(5); // expected-note {{'g' defined here}}<br>
   int i;<br>
@@ -53,13 +56,14 @@ int main(int argc, char **argv) {<br>
   #pragma omp parallel private (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}<br>
   #pragma omp parallel private (argc argv) // expected-error {{expected ',' or ')' in 'private' clause}}<br>
   #pragma omp parallel private (S1) // expected-error {{'S1' does not refer to a value}}<br>
-  #pragma omp parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}}<br>
+  #pragma omp parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}}<br>
   #pragma omp parallel private (argv[1]) // expected-error {{expected variable name}}<br>
   #pragma omp parallel private(ba)<br>
-  #pragma omp parallel private(ca)<br>
-  #pragma omp parallel private(da)<br>
-  #pragma omp parallel private(S2::S2s)<br>
+  #pragma omp parallel private(ca) // expected-error {{shared variable cannot be private}}<br>
+  #pragma omp parallel private(da) // expected-error {{shared variable cannot be private}}<br>
+  #pragma omp parallel private(S2::S2s) // expected-error {{shared variable cannot be private}}<br>
   #pragma omp parallel private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}}<br>
+  #pragma omp parallel private(threadvar) // expected-error {{threadprivate or thread local variable cannot be private}}<br>
   foo();<br>
   #pragma omp parallel private(i)<br>
   #pragma omp parallel private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type 'int &'}}<br>
<br>
Added: cfe/trunk/test/OpenMP/parallel_shared_messages.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_shared_messages.cpp?rev=190183&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_shared_messages.cpp?rev=190183&view=auto</a><br>






==============================================================================<br>
--- cfe/trunk/test/OpenMP/parallel_shared_messages.cpp (added)<br>
+++ cfe/trunk/test/OpenMP/parallel_shared_messages.cpp Fri Sep  6 13:03:48 2013<br>
@@ -0,0 +1,77 @@<br>
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s<br>
+<br>
+void foo() {<br>
+}<br>
+<br>
+bool foobool(int argc) {<br>
+  return argc;<br>
+}<br>
+<br>
+struct S1; // expected-note {{declared here}}<br>
+extern S1 a;<br>
+class S2 {<br>
+  mutable int a;<br>
+public:<br>
+  S2():a(0) { }<br>
+  S2(S2 &s2):a(s2.a) { }<br>
+};<br>
+const S2 b;<br>
+const S2 ba[5];<br>
+class S3 {<br>
+  int a;<br>
+public:<br>
+  S3():a(0) { }<br>
+  S3(S3 &s3):a(s3.a) { }<br>
+};<br>
+const S3 c;<br>
+const S3 ca[5];<br>
+extern const int f;<br>
+class S4 {<br>
+  int a;<br>
+  S4();<br>
+  S4(const S4 &s4);<br>
+public:<br>
+  S4(int v):a(v) { }<br>
+};<br>
+class S5 {<br>
+  int a;<br>
+  S5():a(0) {}<br>
+  S5(const S5 &s5):a(s5.a) { }<br>
+public:<br>
+  S5(int v):a(v) { }<br>
+};<br>
+<br>
+S3 h;<br>
+#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}<br>
+<br>
+int main(int argc, char **argv) {<br>
+  const int d = 5;<br>
+  const int da[5] = { 0 };<br>
+  S4 e(4);<br>
+  S5 g(5);<br>
+  int i;<br>
+  int &j = i;<br>
+  #pragma omp parallel shared // expected-error {{expected '(' after 'shared'}}<br>
+  #pragma omp parallel shared ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}<br>
+  #pragma omp parallel shared () // expected-error {{expected expression}}<br>
+  #pragma omp parallel shared (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}<br>
+  #pragma omp parallel shared (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}<br>
+  #pragma omp parallel shared (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}<br>
+  #pragma omp parallel shared (argc)<br>
+  #pragma omp parallel shared (S1) // expected-error {{'S1' does not refer to a value}}<br>
+  #pragma omp parallel shared (a, b, c, d, f)<br>
+  #pragma omp parallel shared (argv[1]) // expected-error {{expected variable name}}<br>
+  #pragma omp parallel shared(ba)<br>
+  #pragma omp parallel shared(ca)<br>
+  #pragma omp parallel shared(da)<br>
+  #pragma omp parallel shared(e, g)<br>
+  #pragma omp parallel shared(h) // expected-error {{threadprivate or thread local variable cannot be shared}}<br>
+  #pragma omp parallel private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}}<br>
+  foo();<br>
+  #pragma omp parallel private(i)<br>
+  #pragma omp parallel shared(i)<br>
+  #pragma omp parallel shared(j)<br>
+  foo();<br>
+<br>
+  return 0;<br>
+}<br>
<br>
Propchange: cfe/trunk/test/OpenMP/parallel_shared_messages.cpp<br>
------------------------------------------------------------------------------<br>
    svn:eol-style = native<br>
<br>
Propchange: cfe/trunk/test/OpenMP/parallel_shared_messages.cpp<br>
------------------------------------------------------------------------------<br>
    svn:keywords = Author Date Id Rev URL<br>
<br>
Propchange: cfe/trunk/test/OpenMP/parallel_shared_messages.cpp<br>
------------------------------------------------------------------------------<br>
    svn:mime-type = text/plain<br>
<br>
Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Sep  6 13:03:48 2013<br>
@@ -1936,6 +1936,9 @@ void OMPClauseEnqueue::VisitOMPDefaultCl<br>
 void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {<br>
   PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)<br>
 }<br>
+void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) {<br>
+  PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)<br>
+}<br>
 #undef PROCESS_OMP_CLAUSE_LIST<br>
 }<br>
 void EnqueueVisitor::EnqueueChildren(const OMPClause *S) {<br>
<br>
Modified: cfe/trunk/tools/libclang/RecursiveASTVisitor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=190183&r1=190182&r2=190183&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=190183&r1=190182&r2=190183&view=diff</a><br>






==============================================================================<br>
--- cfe/trunk/tools/libclang/RecursiveASTVisitor.h (original)<br>
+++ cfe/trunk/tools/libclang/RecursiveASTVisitor.h Fri Sep  6 13:03:48 2013<br>
@@ -2337,6 +2337,12 @@ bool RecursiveASTVisitor<Derived>::Visit<br>
   return true;<br>
 }<br>
<br>
+template<typename Derived><br>
+bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {<br>
+  PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)<br>
+  return true;<br>
+}<br>
+<br>
 #undef PROCESS_OMP_CLAUSE_LIST<br>
<br>
 // FIXME: look at the following tricky-seeming exprs to see if we<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div><br></div></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>
</blockquote>