Skip to content

Commit 3367d97

Browse files
committed
Avoid initializing the Swift IRGenModule for a given AST context concurrently
rdar://problem/40290306
1 parent 22252f8 commit 3367d97

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/lldb/Symbol/SwiftASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lldb/Utility/Status.h"
2828

2929
#include "llvm/ADT/Optional.h"
30+
#include "llvm/Support/Threading.h"
3031

3132
#include <map>
3233
#include <set>
@@ -822,6 +823,7 @@ class SwiftASTContext : public TypeSystem {
822823
std::unique_ptr<llvm::TargetOptions> m_target_options_ap;
823824
std::unique_ptr<swift::irgen::IRGenerator> m_ir_generator_ap;
824825
std::unique_ptr<swift::irgen::IRGenModule> m_ir_gen_module_ap;
826+
llvm::once_flag m_ir_gen_module_once;
825827
std::unique_ptr<swift::DiagnosticConsumer> m_diagnostic_consumer_ap;
826828
std::unique_ptr<swift::CompilerInvocation> m_compiler_invocation_ap;
827829
std::unique_ptr<DWARFASTParser> m_dwarf_ast_parser_ap;

source/Symbol/SwiftASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,7 +4367,7 @@ SwiftASTContext::GetIRGenerator(swift::IRGenOptions &opts,
43674367
swift::irgen::IRGenModule &SwiftASTContext::GetIRGenModule() {
43684368
VALID_OR_RETURN(*m_ir_gen_module_ap);
43694369

4370-
if (m_ir_gen_module_ap.get() == NULL) {
4370+
llvm::call_once(m_ir_gen_module_once, [this]() {
43714371
// Make sure we have a good ClangImporter.
43724372
GetClangImporter();
43734373

@@ -4410,7 +4410,7 @@ swift::irgen::IRGenModule &SwiftASTContext::GetIRGenModule() {
44104410
llvm_module->setTargetTriple(triple);
44114411
}
44124412
}
4413-
}
4413+
});
44144414
return *m_ir_gen_module_ap;
44154415
}
44164416

0 commit comments

Comments
 (0)