Skip to content

Commit b72f84d

Browse files
authored
revert db7696e and 4a88836 (#427) (#448)
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 6cf0cbc commit b72f84d

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

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

215215
try {
216+
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
216217
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());
217218

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

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

415415
try {
416416
CompileOptionsParser optionsParser("200");

0 commit comments

Comments
 (0)