diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-05-22 12:33:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-22 12:33:52 -0700 |
commit | 9e306ad4600c4d3392c194a8be88919ee758425c (patch) | |
tree | f8b15171e92d056e9006bcbe36d534a9d73155d9 /clang/lib/Frontend/FrontendActions.cpp | |
parent | 2b8bff6f66fd90ac658d0ae0d7f9a83ffadfd77f (diff) | |
download | llvm-9e306ad4600c4d3392c194a8be88919ee758425c.zip llvm-9e306ad4600c4d3392c194a8be88919ee758425c.tar.gz llvm-9e306ad4600c4d3392c194a8be88919ee758425c.tar.bz2 |
[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)
The `DiagnosticOptions` class is currently intrusively
reference-counted, which makes reasoning about its lifetime very
difficult in some cases. For example, `CompilerInvocation` owns the
`DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and
only exposes an accessor returning `DiagnosticOptions &`. One would
think this gives `CompilerInvocation` exclusive ownership of the object,
but that's not the case:
```c++
void shareOwnership(CompilerInvocation &CI) {
llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions();
// ...
}
```
This is a perfectly valid pattern that is being actually used in the
codebase.
I would like to ensure the ownership of `DiagnosticOptions` by
`CompilerInvocation` is guaranteed to be exclusive. This can be
leveraged for a copy-on-write optimization later on. This PR changes
usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and
`lldb` to not be intrusively reference-counted.
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 8c75e1a..d14d091 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -685,21 +685,21 @@ namespace { return false; } - bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, + bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts, StringRef ModuleFilename, bool Complain) override { Out.indent(2) << "Diagnostic options:\n"; -#define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name); -#define ENUM_DIAGOPT(Name, Type, Bits, Default) \ - Out.indent(4) << #Name << ": " << DiagOpts->get##Name() << "\n"; -#define VALUE_DIAGOPT(Name, Bits, Default) \ - Out.indent(4) << #Name << ": " << DiagOpts->Name << "\n"; +#define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts.Name, #Name); +#define ENUM_DIAGOPT(Name, Type, Bits, Default) \ + Out.indent(4) << #Name << ": " << DiagOpts.get##Name() << "\n"; +#define VALUE_DIAGOPT(Name, Bits, Default) \ + Out.indent(4) << #Name << ": " << DiagOpts.Name << "\n"; #include "clang/Basic/DiagnosticOptions.def" Out.indent(4) << "Diagnostic flags:\n"; - for (const std::string &Warning : DiagOpts->Warnings) + for (const std::string &Warning : DiagOpts.Warnings) Out.indent(6) << "-W" << Warning << "\n"; - for (const std::string &Remark : DiagOpts->Remarks) + for (const std::string &Remark : DiagOpts.Remarks) Out.indent(6) << "-R" << Remark << "\n"; return false; |