Skip to content

Commit 53b8f12

Browse files
authored
revert db7696e and 4a88836 (#427) (#449)
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 2a9a243 commit 53b8f12

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

@@ -212,6 +212,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
212212
CommonClangInitialize();
213213

214214
try {
215+
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
215216
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());
216217

217218
// Create the clang compiler
@@ -223,8 +224,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
223224
// Prepare error log
224225
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
225226
{
226-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
227-
228227
// Parse options
229228
optionsParser.processOptions(pszOptions, pszOptionsEx);
230229

@@ -343,7 +342,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
343342
err_ostream.flush();
344343
}
345344
{
346-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
347345
if (pBinaryResult) {
348346
*pBinaryResult = pResult.release();
349347
}

options_compile.cpp

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

4040
using namespace llvm::opt;
4141

42-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileOptionsMutex;
42+
extern llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
4343

4444
static const OptTable::Info ClangOptionsInfoTable[] = {
4545
#define PREFIX(NAME, VALUE)
@@ -430,7 +430,7 @@ extern "C" CC_DLL_EXPORT bool CheckCompileOptions(const char *pszOptions,
430430
size_t uiUnknownOptionsSize) {
431431
// LLVM doesn't guarantee thread safety,
432432
// therefore we serialize execution of LLVM code.
433-
llvm::sys::SmartScopedLock<true> compileOptionsGuard {*compileOptionsMutex};
433+
llvm::sys::SmartScopedLock<true> compileOptionsGuard{*compileMutex};
434434

435435
try {
436436
CompileOptionsParser optionsParser("200");

0 commit comments

Comments
 (0)