Skip to content

Commit bd1b2aa

Browse files
committed
[clangd] Preamble owns TargetOptions
1 parent 84445a4 commit bd1b2aa

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,10 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
711711
Result->Marks = CapturedInfo.takeMarks();
712712
Result->StatCache = StatCache;
713713
Result->MainIsIncludeGuarded = CapturedInfo.isMainFileIncludeGuarded();
714-
Result->TargetOpts = CI.TargetOpts;
714+
// Move the options instead of copying them. The invocation doesn't need
715+
// them anymore.
716+
Result->TargetOpts =
717+
std::make_unique<TargetOptions>(std::move(CI.getTargetOpts()));
715718
if (PreambleCallback) {
716719
trace::Span Tracer("Running PreambleCallback");
717720
auto Ctx = CapturedInfo.takeLife();
@@ -932,7 +935,7 @@ void PreamblePatch::apply(CompilerInvocation &CI) const {
932935
// ParsedASTTest.PreambleWithDifferentTarget.
933936
// Make sure this is a deep copy, as the same Baseline might be used
934937
// concurrently.
935-
*CI.TargetOpts = *Baseline->TargetOpts;
938+
CI.getTargetOpts() = *Baseline->TargetOpts;
936939

937940
// No need to map an empty file.
938941
if (PatchContents.empty())

clang-tools-extra/clangd/Preamble.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct PreambleData {
103103
// Target options used when building the preamble. Changes in target can cause
104104
// crashes when deserializing preamble, this enables consumers to use the
105105
// same target (without reparsing CompileCommand).
106-
std::shared_ptr<TargetOptions> TargetOpts = nullptr;
106+
std::unique_ptr<TargetOptions> TargetOpts = nullptr;
107107
PrecompiledPreamble Preamble;
108108
std::vector<Diag> Diags;
109109
// Processes like code completions and go-to-definitions will need #include

0 commit comments

Comments
 (0)