diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-04-28 07:43:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-28 07:43:26 -0700 |
commit | 985410f87f2d19910a8d327527fd30062b042b63 (patch) | |
tree | 1c4cb157ec0848c56fce54165e6237c9e7f1fc79 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | ba420d8122239592a1fb7ad6efd2c186aecfdef5 (diff) | |
download | llvm-985410f87f2d19910a8d327527fd30062b042b63.zip llvm-985410f87f2d19910a8d327527fd30062b042b63.tar.gz llvm-985410f87f2d19910a8d327527fd30062b042b63.tar.bz2 |
[clang] Hide the `TargetOptions` pointer from `CompilerInvocation` (#106271)
This PR hides the reference-counted pointer that holds `TargetOptions`
from the public API of `CompilerInvocation`. This gives
`CompilerInvocation` an exclusive control over the lifetime of this
member, which will eventually be leveraged to implement a copy-on-write
behavior.
There are two clients that currently share ownership of that pointer:
* `TargetInfo` - This was refactored to hold a non-owning reference to
`TargetOptions`. The options object is typically owned by the
`CompilerInvocation` or by the new `CompilerInstance::AuxTargetOpts` for
the auxiliary target. This needed a bit of care in `ASTUnit::Parse()` to
keep the `CompilerInvocation` alive.
* `clangd::PreambleData` - This was refactored to exclusively own the
`TargetOptions` that get moved out of the `CompilerInvocation`.
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 1526ea5..2d6ab87 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -110,7 +110,7 @@ void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; } bool CompilerInstance::createTarget() { // Create the target instance. setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), - getInvocation().TargetOpts)); + getInvocation().getTargetOpts())); if (!hasTarget()) return false; @@ -119,14 +119,14 @@ bool CompilerInstance::createTarget() { if (!getAuxTarget() && (getLangOpts().CUDA || getLangOpts().isTargetDevice()) && !getFrontendOpts().AuxTriple.empty()) { - auto TO = std::make_shared<TargetOptions>(); + auto &TO = AuxTargetOpts = std::make_unique<TargetOptions>(); TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple); if (getFrontendOpts().AuxTargetCPU) TO->CPU = *getFrontendOpts().AuxTargetCPU; if (getFrontendOpts().AuxTargetFeatures) TO->FeaturesAsWritten = *getFrontendOpts().AuxTargetFeatures; TO->HostTriple = getTarget().getTriple().str(); - setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO)); + setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), *TO)); } if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) { |