This revision was automatically updated to reflect the committed changes.
Closed by commit rL363009: [Frontend] SetUpDiagnosticLog should handle unowned
diagnostic consumer (authored by arphaman, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D63101?vs=203910&id=203931#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63101/new/
https://reviews.llvm.org/D63101
Files:
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -232,9 +232,13 @@
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,
Index: cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
===================================================================
--- cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
+++ cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
@@ -8,6 +8,7 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ToolOutputFile.h"
@@ -70,4 +71,21 @@
ASSERT_TRUE(Instance.getFileManager().getFile("vfs-virtual.file"));
}
+TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
+ auto DiagOpts = new DiagnosticOptions();
+ DiagOpts->DiagnosticLogFile = "log.diags";
+
+ // Create the diagnostic engine with unowned consumer.
+ std::string DiagnosticOutput;
+ llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+ auto DiagPrinter = llvm::make_unique<TextDiagnosticPrinter>(
+ DiagnosticsOS, new DiagnosticOptions());
+ CompilerInstance Instance;
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags = Instance.createDiagnostics(
+ DiagOpts, DiagPrinter.get(), /*ShouldOwnClient=*/false);
+
+ Diags->Report(diag::err_expected) << "no crash";
+ ASSERT_EQ(DiagnosticsOS.str(), "error: expected no crash\n");
+}
+
} // anonymous namespace
Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -232,9 +232,13 @@
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,
Index: cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
===================================================================
--- cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
+++ cfe/trunk/unittests/Frontend/CompilerInstanceTest.cpp
@@ -8,6 +8,7 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ToolOutputFile.h"
@@ -70,4 +71,21 @@
ASSERT_TRUE(Instance.getFileManager().getFile("vfs-virtual.file"));
}
+TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
+ auto DiagOpts = new DiagnosticOptions();
+ DiagOpts->DiagnosticLogFile = "log.diags";
+
+ // Create the diagnostic engine with unowned consumer.
+ std::string DiagnosticOutput;
+ llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+ auto DiagPrinter = llvm::make_unique<TextDiagnosticPrinter>(
+ DiagnosticsOS, new DiagnosticOptions());
+ CompilerInstance Instance;
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags = Instance.createDiagnostics(
+ DiagOpts, DiagPrinter.get(), /*ShouldOwnClient=*/false);
+
+ Diags->Report(diag::err_expected) << "no crash";
+ ASSERT_EQ(DiagnosticsOS.str(), "error: expected no crash\n");
+}
+
} // anonymous namespace
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits