From: Reid Kleckner Date: Wed, 17 Dec 2014 20:23:11 +0000 (+0000) Subject: Destroy the diagnostic client first in ~DiagnosticEngine X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9fe7e8295aae20b2d96070eebb415321227a6d0;p=clang Destroy the diagnostic client first in ~DiagnosticEngine Add a comment and a test to ~DiagnosticEngine about the ordering requirements on the teardown of DiagnosticConsumer. This could also be accomplished by rearranging the fields of ~DiagnosticEngine, but I felt that this was a better, more explicit solution. This fixes PR21911, an issue that occurred after the unique_ptr migration in r222193. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224454 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 31a29fa200..91e94db802 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -347,6 +347,7 @@ public: DiagnosticOptions *DiagOpts, DiagnosticConsumer *client = nullptr, bool ShouldOwnClient = true); + ~DiagnosticsEngine(); const IntrusiveRefCntPtr &getDiagnosticIDs() const { return Diags; diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 5c066efa10..a892946608 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -61,6 +61,12 @@ DiagnosticsEngine::DiagnosticsEngine( Reset(); } +DiagnosticsEngine::~DiagnosticsEngine() { + // If we own the diagnostic client, destroy it first so that it can access the + // engine from its destructor. + setClient(nullptr); +} + void DiagnosticsEngine::setClient(DiagnosticConsumer *client, bool ShouldOwnClient) { Owner.reset(ShouldOwnClient ? client : nullptr); diff --git a/test/Frontend/verify-unknown-arg.c b/test/Frontend/verify-unknown-arg.c new file mode 100644 index 0000000000..5767daedca --- /dev/null +++ b/test/Frontend/verify-unknown-arg.c @@ -0,0 +1,6 @@ +// RUN: not %clang_cc1 -asdf -verify %s 2>&1 | FileCheck %s + +// expected-no-diagnostics + +// CHECK: error: 'error' diagnostics seen but not expected: +// CHECK-NEXT: (frontend): unknown argument: '-asdf'