Skip to content

Commit bf37b13

Browse files
authored
revert db7696e and 4a88836 (#427) (#451)
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 ed655f8 commit bf37b13

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

90-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileMutex;
90+
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
9191

9292
void CommonClangTerminate() {
9393
llvm::llvm_shutdown();
@@ -217,6 +217,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
217217
CommonClangInitialize();
218218

219219
try {
220+
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
220221
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());
221222

222223
// Create the clang compiler
@@ -228,8 +229,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
228229
// Prepare error log
229230
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
230231
{
231-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
232-
233232
// Parse options
234233
optionsParser.processOptions(pszOptions, pszOptionsEx);
235234

@@ -358,7 +357,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
358357
err_ostream.flush();
359358
}
360359
{
361-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
362360
if (pBinaryResult) {
363361
*pBinaryResult = pResult.release();
364362
}

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)