[OPENMP] Fix crash on private variables not used in OpenMP region in templates.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 2 Apr 2015 13:07:08 +0000 (13:07 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 2 Apr 2015 13:07:08 +0000 (13:07 +0000)
llvm-svn: 233913

clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/test/OpenMP/parallel_firstprivate_codegen.cpp

index 7b449537c7dd4600474fd60fb04a5f49a8480103..92552207813aba323b30c9c2e65a010da3c63894 100644 (file)
@@ -1199,7 +1199,7 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
     if (isOpenMPPrivate(Clause->getClauseKind())) {
       for (auto *VarRef : Clause->children()) {
         if (auto *E = cast_or_null<Expr>(VarRef)) {
-          MarkDeclarationsReferencedInExpr(cast<Expr>(E));
+          MarkDeclarationsReferencedInExpr(E);
         }
       }
     }
index 6116a78dc7b69be46da9e9dbfdacd161a5a7eaf5..df0e4b316d7b3dc5104ac98608ff37c59abc96c1 100644 (file)
@@ -6670,7 +6670,16 @@ StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
     if (!D->getAssociatedStmt()) {
       return StmtError();
     }
-    AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
+    getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
+                                                  /*CurScope=*/nullptr);
+    StmtResult Body;
+    {
+      Sema::CompoundScopeRAII CompoundScope(getSema());
+      Body = getDerived().TransformStmt(
+          cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
+    }
+    AssociatedStmt =
+        getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
     if (AssociatedStmt.isInvalid()) {
       return StmtError();
     }
index d68aba3f70237e687a9db759cf443c23dbd04778..2be3bedfce7607db4a6a1879ba4ed2b6c0fb5273 100644 (file)
@@ -45,6 +45,8 @@ T tmain() {
     vec[0] = t_var;
     s_arr[0] = var;
   }
+#pragma omp parallel firstprivate(t_var)
+  {}
   return T();
 }