]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix crash on private variables not used in OpenMP region.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 2 Apr 2015 07:48:16 +0000 (07:48 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 2 Apr 2015 07:48:16 +0000 (07:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233902 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Parse/ParseOpenMP.cpp
lib/Sema/SemaOpenMP.cpp
test/OpenMP/parallel_firstprivate_codegen.cpp

index 1d32574cc607a36b150b37f57afd8681fab47081..3f310717902a1370033699abf9e9a2c79d9374f3 100644 (file)
@@ -7429,6 +7429,13 @@ public:
 
   /// \brief Initialization of captured region for OpenMP region.
   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
+  /// \brief End of OpenMP region.
+  ///
+  /// \param S Statement associated with the current OpenMP region.
+  /// \param Clauses List of clauses for the current OpenMP region.
+  ///
+  /// \returns Statement for finished OpenMP region.
+  StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses);
   StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
                                             const DeclarationNameInfo &DirName,
                                             ArrayRef<OMPClause *> Clauses,
index 764619aae6f343e0b89f0152b30f2d96f1947161..143ef704db90a822a17f769d80110f5d06b6907d 100644 (file)
@@ -257,13 +257,8 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) {
       // Parse statement
       AssociatedStmt = ParseStatement();
       Actions.ActOnFinishOfCompoundStmt();
-      if (!AssociatedStmt.isUsable()) {
-        Actions.ActOnCapturedRegionError();
-        CreateDirective = false;
-      } else {
-        AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.get());
-        CreateDirective = AssociatedStmt.isUsable();
-      }
+      AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
+      CreateDirective = AssociatedStmt.isUsable();
     }
     if (CreateDirective)
       Directive = Actions.ActOnOpenMPExecutableDirective(
index 80ca072e2dd5e5d11a2db5dd3bd5f2bab7a8ed4e..7b449537c7dd4600474fd60fb04a5f49a8480103 100644 (file)
@@ -1187,6 +1187,26 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
   }
 }
 
+StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
+                                      ArrayRef<OMPClause *> Clauses) {
+  if (!S.isUsable()) {
+    ActOnCapturedRegionError();
+    return StmtError();
+  }
+  // Mark all variables in private list clauses as used in inner region. This is
+  // required for proper codegen.
+  for (auto *Clause : Clauses) {
+    if (isOpenMPPrivate(Clause->getClauseKind())) {
+      for (auto *VarRef : Clause->children()) {
+        if (auto *E = cast_or_null<Expr>(VarRef)) {
+          MarkDeclarationsReferencedInExpr(cast<Expr>(E));
+        }
+      }
+    }
+  }
+  return ActOnCapturedRegionEnd(S.get());
+}
+
 static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
                                   OpenMPDirectiveKind CurrentRegion,
                                   const DeclarationNameInfo &CurrentName,
index 25cf2b200c33ad21adda45b70654b1eb6f0aec44..d68aba3f70237e687a9db759cf443c23dbd04778 100644 (file)
@@ -136,6 +136,8 @@ int main() {
     vec[0] = t_var;
     s_arr[0] = var;
   }
+#pragma omp parallel firstprivate(t_var)
+  {}
   return tmain<int>();
 #endif
 }