From 91797559acb50c46c77aa200253caefc6acdd11c Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 18 Mar 2015 04:13:55 +0000 Subject: [PATCH] [OPENMP] Fix crash on code emitting if errors are found. Codegen for threadprivate variables (and in some other cases) may cause crash of the compiler if some diagnostic is produced later. This happens because some of the autogenerated globals are not removed from InternalVars StringMap when llvm::Module is reset. Differential Revision: http://reviews.llvm.org/D8360 llvm-svn: 232610 --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++++ clang/lib/CodeGen/CGOpenMPRuntime.h | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 2 ++ clang/test/OpenMP/threadprivate_messages.cpp | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 9d33b16fab74..257558380136 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -211,6 +211,10 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM) KmpCriticalNameTy = llvm::ArrayType::get(CGM.Int32Ty, /*NumElements*/ 8); } +void CGOpenMPRuntime::clear() { + InternalVars.clear(); +} + llvm::Value * CGOpenMPRuntime::emitOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar) { diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h index e9f389de3ffe..a3f957045d70 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.h +++ b/clang/lib/CodeGen/CGOpenMPRuntime.h @@ -278,6 +278,7 @@ class CGOpenMPRuntime { public: explicit CGOpenMPRuntime(CodeGenModule &CGM); virtual ~CGOpenMPRuntime() {} + virtual void clear(); /// \brief Emits outlined function for the specified OpenMP directive \a D. /// This outlined function has type void(*)(kmp_int32 *ThreadID, kmp_int32 diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c91de6df9e93..b25f315709e9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -323,6 +323,8 @@ void CodeGenModule::checkAliases() { void CodeGenModule::clear() { DeferredDeclsToEmit.clear(); + if (OpenMPRuntime) + OpenMPRuntime->clear(); } void InstrProfStats::reportDiagnostics(DiagnosticsEngine &Diags, diff --git a/clang/test/OpenMP/threadprivate_messages.cpp b/clang/test/OpenMP/threadprivate_messages.cpp index 27b36fbe024c..1aaf2d0cf72a 100644 --- a/clang/test/OpenMP/threadprivate_messages.cpp +++ b/clang/test/OpenMP/threadprivate_messages.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp=libiomp5 -ferror-limit 100 %s +// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp=libiomp5 -ferror-limit 100 -emit-llvm -o - %s #pragma omp threadprivate // expected-error {{expected '(' after 'threadprivate'}} #pragma omp threadprivate( // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}