From: Alexey Bataev Date: Thu, 2 Apr 2015 07:48:16 +0000 (+0000) Subject: [OPENMP] Fix crash on private variables not used in OpenMP region. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec2dad61481ab20c2a579bf0edec8223aa56f9dc;p=clang [OPENMP] Fix crash on private variables not used in OpenMP region. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233902 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 1d32574cc6..3f31071790 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -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 Clauses); StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, ArrayRef Clauses, diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 764619aae6..143ef704db 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -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( diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 80ca072e2d..7b449537c7 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -1187,6 +1187,26 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { } } +StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, + ArrayRef 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(VarRef)) { + MarkDeclarationsReferencedInExpr(cast(E)); + } + } + } + } + return ActOnCapturedRegionEnd(S.get()); +} + static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, OpenMPDirectiveKind CurrentRegion, const DeclarationNameInfo &CurrentName, diff --git a/test/OpenMP/parallel_firstprivate_codegen.cpp b/test/OpenMP/parallel_firstprivate_codegen.cpp index 25cf2b200c..d68aba3f70 100644 --- a/test/OpenMP/parallel_firstprivate_codegen.cpp +++ b/test/OpenMP/parallel_firstprivate_codegen.cpp @@ -136,6 +136,8 @@ int main() { vec[0] = t_var; s_arr[0] = var; } +#pragma omp parallel firstprivate(t_var) + {} return tmain(); #endif }