Skip to content

Commit 76bc7f9

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

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

93-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileMutex;
93+
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
9494

9595
void CommonClangTerminate() {
9696
llvm::llvm_shutdown();
@@ -206,6 +206,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
206206
CommonClangInitialize();
207207

208208
try {
209+
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
209210
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());
210211

211212
// Create the clang compiler
@@ -216,8 +217,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
216217
// Prepare error log
217218
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
218219
{
219-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
220-
221220
// Parse options
222221
optionsParser.processOptions(pszOptions, pszOptionsEx);
223222

@@ -339,7 +338,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
339338
err_ostream.flush();
340339
}
341340
{
342-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
343341
if (pBinaryResult) {
344342
*pBinaryResult = pResult.release();
345343
}

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)
@@ -320,7 +320,7 @@ extern "C" CC_DLL_EXPORT bool CheckCompileOptions(const char *pszOptions,
320320
size_t uiUnknownOptionsSize) {
321321
// LLVM doesn't guarantee thread safety,
322322
// therefore we serialize execution of LLVM code.
323-
llvm::sys::SmartScopedLock<true> compileOptionsGuard {*compileOptionsMutex};
323+
llvm::sys::SmartScopedLock<true> compileOptionsGuard{*compileMutex};
324324

325325
try {
326326
CompileOptionsParser optionsParser("200");

0 commit comments

Comments
 (0)