Skip to content

Commit 5639fd9

Browse files
authored
revert db7696e and 4a88836 (#427) (#446)
llvm-related variable initialization, clang::ExecuteCompilerInvocation and llvm-spirv aren't thread safe. (cherry picked from commit 76bc7f9)
1 parent c2f03fc commit 5639fd9

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
@@ -93,7 +93,7 @@ static volatile bool lazyCCInit =
9393
true; // the flag must be 'volatile' to prevent caching in a CPU register
9494
static llvm::sys::Mutex lazyCCInitMutex;
9595

96-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileMutex;
96+
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
9797

9898
void CommonClangTerminate() {
9999
llvm::llvm_shutdown();
@@ -222,6 +222,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
222222
CommonClangInitialize();
223223

224224
try {
225+
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
225226
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());
226227

227228
// Create the clang compiler
@@ -231,8 +232,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
231232
CompileOptionsParser optionsParser(pszOpenCLVer);
232233
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
233234
{
234-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
235-
236235
// Parse options
237236
optionsParser.processOptions(pszOptions, pszOptionsEx);
238237
// Prepare error log
@@ -360,7 +359,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
360359
err_ostream.flush();
361360
}
362361
{
363-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
364362
if (pBinaryResult) {
365363
*pBinaryResult = pResult.release();
366364
}

options_compile.cpp

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

3939
using namespace llvm::opt;
4040

41-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileOptionsMutex;
41+
extern llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
4242

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

428428
try {
429429
CompileOptionsParser optionsParser("200");

0 commit comments

Comments
 (0)