Skip to content

Commit d4d28b8

Browse files
committed
[clangd] Preamble owns TargetOptions
1 parent 7b73dfc commit d4d28b8

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
@@ -713,7 +713,10 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
713713
Result->Marks = CapturedInfo.takeMarks();
714714
Result->StatCache = StatCache;
715715
Result->MainIsIncludeGuarded = CapturedInfo.isMainFileIncludeGuarded();
716-
Result->TargetOpts = CI.TargetOpts;
716+
// Move the options instead of copying them. The invocation doesn't need
717+
// them anymore.
718+
Result->TargetOpts =
719+
std::make_unique<TargetOptions>(std::move(CI.getTargetOpts()));
717720
if (PreambleCallback) {
718721
trace::Span Tracer("Running PreambleCallback");
719722
auto Ctx = CapturedInfo.takeLife();
@@ -934,7 +937,7 @@ void PreamblePatch::apply(CompilerInvocation &CI) const {
934937
// ParsedASTTest.PreambleWithDifferentTarget.
935938
// Make sure this is a deep copy, as the same Baseline might be used
936939
// concurrently.
937-
*CI.TargetOpts = *Baseline->TargetOpts;
940+
CI.getTargetOpts() = *Baseline->TargetOpts;
938941

939942
// No need to map an empty file.
940943
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)