aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 9c33910..3c23073 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -125,14 +125,21 @@ static Expected<std::optional<uint32_t>> parseToleranceOption(StringRef Arg) {
// Initialization.
//===----------------------------------------------------------------------===//
+namespace {
template <class T> std::shared_ptr<T> make_shared_copy(const T &X) {
return std::make_shared<T>(X);
}
+template <class T>
+llvm::IntrusiveRefCntPtr<T> makeIntrusiveRefCntCopy(const T &X) {
+ return llvm::makeIntrusiveRefCnt<T>(X);
+}
+} // namespace
+
CompilerInvocationBase::CompilerInvocationBase()
: LangOpts(std::make_shared<LangOptions>()),
TargetOpts(std::make_shared<TargetOptions>()),
- DiagnosticOpts(std::make_shared<DiagnosticOptions>()),
+ DiagnosticOpts(llvm::makeIntrusiveRefCnt<DiagnosticOptions>()),
HSOpts(std::make_shared<HeaderSearchOptions>()),
PPOpts(std::make_shared<PreprocessorOptions>()),
AnalyzerOpts(std::make_shared<AnalyzerOptions>()),
@@ -149,7 +156,7 @@ CompilerInvocationBase::deep_copy_assign(const CompilerInvocationBase &X) {
if (this != &X) {
LangOpts = make_shared_copy(X.getLangOpts());
TargetOpts = make_shared_copy(X.getTargetOpts());
- DiagnosticOpts = make_shared_copy(X.getDiagnosticOpts());
+ DiagnosticOpts = makeIntrusiveRefCntCopy(X.getDiagnosticOpts());
HSOpts = make_shared_copy(X.getHeaderSearchOpts());
PPOpts = make_shared_copy(X.getPreprocessorOpts());
AnalyzerOpts = make_shared_copy(X.getAnalyzerOpts());
@@ -195,6 +202,7 @@ CompilerInvocation::operator=(const CowCompilerInvocation &X) {
return *this;
}
+namespace {
template <typename T>
T &ensureOwned(std::shared_ptr<T> &Storage) {
if (Storage.use_count() > 1)
@@ -202,6 +210,14 @@ T &ensureOwned(std::shared_ptr<T> &Storage) {
return *Storage;
}
+template <typename T>
+T &ensureOwned(llvm::IntrusiveRefCntPtr<T> &Storage) {
+ if (Storage.useCount() > 1)
+ Storage = llvm::makeIntrusiveRefCnt<T>(*Storage);
+ return *Storage;
+}
+} // namespace
+
LangOptions &CowCompilerInvocation::getMutLangOpts() {
return ensureOwned(LangOpts);
}
@@ -828,8 +844,7 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate,
};
// Setup a dummy DiagnosticsEngine.
- DiagnosticOptions DummyDiagOpts;
- DiagnosticsEngine DummyDiags(new DiagnosticIDs(), DummyDiagOpts);
+ DiagnosticsEngine DummyDiags(new DiagnosticIDs(), new DiagnosticOptions());
DummyDiags.setClient(new TextDiagnosticBuffer());
// Run the first parse on the original arguments with the dummy invocation and
@@ -2648,11 +2663,9 @@ clang::CreateAndPopulateDiagOpts(ArrayRef<const char *> Argv) {
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
DiagnosticsEngine *Diags,
bool DefaultDiagColor) {
- std::optional<DiagnosticOptions> IgnoringDiagOpts;
std::optional<DiagnosticsEngine> IgnoringDiags;
if (!Diags) {
- IgnoringDiagOpts.emplace();
- IgnoringDiags.emplace(new DiagnosticIDs(), *IgnoringDiagOpts,
+ IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(),
new IgnoringDiagConsumer());
Diags = &*IgnoringDiags;
}