Skip to content

Commit cf77b19

Browse files
authored
revert db7696e and 4a88836 (#427) (#447)
llvm-related variable initialization, clang::ExecuteCompilerInvocation and llvm-spirv aren't thread safe, at least for 90 branch. (cherry picked from commit 76bc7f9)
1 parent aa7d263 commit cf77b19

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

common_clang.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static volatile bool lazyCCInit =
8585
true; // the flag must be 'volatile' to prevent caching in a CPU register
8686
static llvm::sys::Mutex lazyCCInitMutex;
8787

88-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileMutex;
88+
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
8989

9090
void CommonClangTerminate() { llvm::llvm_shutdown(); }
9191

@@ -199,6 +199,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
199199
CommonClangInitialize();
200200

201201
try {
202+
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
202203
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());
203204

204205
// Create the clang compiler
@@ -210,8 +211,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
210211
// Prepare error log
211212
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
212213
{
213-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
214-
215214
// Parse options
216215
optionsParser.processOptions(pszOptions, pszOptionsEx);
217216

@@ -330,7 +329,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
330329
err_ostream.flush();
331330
}
332331
{
333-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
334332
if (pBinaryResult) {
335333
*pBinaryResult = pResult.release();
336334
}

options_compile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Copyright (c) Intel Corporation (2009-2017).
3636

3737
using namespace llvm::opt;
3838

39-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileOptionsMutex;
39+
extern llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
4040

4141
static const OptTable::Info ClangOptionsInfoTable[] = {
4242
#define PREFIX(NAME, VALUE)
@@ -310,7 +310,7 @@ extern "C" CC_DLL_EXPORT bool CheckCompileOptions(const char *pszOptions,
310310
size_t uiUnknownOptionsSize) {
311311
// LLVM doesn't guarantee thread safety,
312312
// therefore we serialize execution of LLVM code.
313-
llvm::sys::SmartScopedLock<true> compileOptionsGuard {*compileOptionsMutex};
313+
llvm::sys::SmartScopedLock<true> compileOptionsGuard{*compileMutex};
314314

315315
try {
316316
CompileOptionsParser optionsParser("200");

0 commit comments

Comments
 (0)