r221884 - Support non-owned DiagnosticConsumer in SetupSerializedDiagnostics
Alexander Kornienko
alexfh at google.com
Thu Nov 13 05:08:28 PST 2014
Author: alexfh
Date: Thu Nov 13 07:08:27 2014
New Revision: 221884
URL: http://llvm.org/viewvc/llvm-project?rev=221884&view=rev
Log:
Support non-owned DiagnosticConsumer in SetupSerializedDiagnostics
This fixes an assertion when running clang-tidy on a file having
--serialize-diagnostics in compiler options. Committing a regression test
for clang-tidy separately.
Patch by Aaron Wishnick!
Modified:
cfe/trunk/include/clang/Frontend/ChainedDiagnosticConsumer.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
Modified: cfe/trunk/include/clang/Frontend/ChainedDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ChainedDiagnosticConsumer.h?rev=221884&r1=221883&r2=221884&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ChainedDiagnosticConsumer.h (original)
+++ cfe/trunk/include/clang/Frontend/ChainedDiagnosticConsumer.h Thu Nov 13 07:08:27 2014
@@ -22,13 +22,20 @@ class LangOptions;
/// diagnostics should be included in counts.
class ChainedDiagnosticConsumer : public DiagnosticConsumer {
virtual void anchor();
- std::unique_ptr<DiagnosticConsumer> Primary;
+ std::unique_ptr<DiagnosticConsumer> OwningPrimary;
+ DiagnosticConsumer *Primary;
std::unique_ptr<DiagnosticConsumer> Secondary;
public:
ChainedDiagnosticConsumer(std::unique_ptr<DiagnosticConsumer> Primary,
std::unique_ptr<DiagnosticConsumer> Secondary)
- : Primary(std::move(Primary)), Secondary(std::move(Secondary)) {}
+ : OwningPrimary(std::move(Primary)), Primary(OwningPrimary.get()),
+ Secondary(std::move(Secondary)) {}
+
+ /// \brief Construct without taking ownership of \c Primary.
+ ChainedDiagnosticConsumer(DiagnosticConsumer *Primary,
+ std::unique_ptr<DiagnosticConsumer> Secondary)
+ : Primary(Primary), Secondary(std::move(Secondary)) {}
void BeginSourceFile(const LangOptions &LO,
const Preprocessor *PP) override {
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=221884&r1=221883&r2=221884&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Nov 13 07:08:27 2014
@@ -170,10 +170,14 @@ static void SetupSerializedDiagnostics(D
auto SerializedConsumer =
clang::serialized_diags::create(OutputFile, DiagOpts);
- assert(Diags.ownsClient());
- Diags.setClient(new ChainedDiagnosticConsumer(
- std::unique_ptr<DiagnosticConsumer>(Diags.takeClient()),
- std::move(SerializedConsumer)));
+ if (Diags.ownsClient()) {
+ Diags.setClient(new ChainedDiagnosticConsumer(
+ std::unique_ptr<DiagnosticConsumer>(Diags.takeClient()),
+ std::move(SerializedConsumer)));
+ } else {
+ Diags.setClient(new ChainedDiagnosticConsumer(
+ Diags.takeClient(), std::move(SerializedConsumer)));
+ }
}
void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client,
More information about the cfe-commits
mailing list