From 88377d8db79c46658f41dbf2503225265036444e Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 10 Jun 2019 23:32:42 +0000 Subject: [Frontend] SetUpDiagnosticLog should handle unowned diagnostic consumer in the compiler The function SetUpDiagnosticLog that was called from createDiagnostics didn't handle the case where the diagnostics engine didn't own the diagnostics consumer. This is a potential problem for a clang tool, in particular some of the follow-up patches for clang-scan-deps will need this fix. Differential Revision: https://reviews.llvm.org/D63101 llvm-svn: 363009 --- clang/lib/Frontend/CompilerInstance.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'clang/lib/Frontend/CompilerInstance.cpp') diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 9c70a70ed7e..fd33b85b31d 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -232,9 +232,13 @@ static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts, std::move(StreamOwner)); if (CodeGenOpts) Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags); - assert(Diags.ownsClient()); - Diags.setClient( - new ChainedDiagnosticConsumer(Diags.takeClient(), std::move(Logger))); + if (Diags.ownsClient()) { + Diags.setClient( + new ChainedDiagnosticConsumer(Diags.takeClient(), std::move(Logger))); + } else { + Diags.setClient( + new ChainedDiagnosticConsumer(Diags.getClient(), std::move(Logger))); + } } static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, -- cgit v1.2.3