From: Daniel Dunbar Date: Wed, 14 Mar 2012 09:49:36 +0000 (+0000) Subject: [Basic] Change DiagnosticBuilder to use a separate status variable to track whether... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7059a1cbc29444bec19380059a62db085eb92964;p=clang [Basic] Change DiagnosticBuilder to use a separate status variable to track whether the builder is active. - This may seem superflous, but actually this allows the optimizer to more easily eliminate the isActive() checks needed by the SemaDiagnosticBuilder and DiagnosticBuilder dtors. And by more easily, I mean the current LLVM is actually able to do one and not the other. :) This is good for another 20k code size reduction. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152709 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 43747a1810..1634306fc3 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -772,10 +772,17 @@ class DiagnosticBuilder { mutable DiagnosticsEngine *DiagObj; mutable unsigned NumArgs, NumRanges, NumFixits; + /// \brief Status variable indicating if this diagnostic is still active. + /// + // NOTE: This field is redundant with DiagObj (IsActive iff (DiagObj == 0)), + // but LLVM is not currently smart enough to eliminate the null check that + // Emit() would end up with if we used that as our status variable. + mutable bool IsActive; + void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT friend class DiagnosticsEngine; explicit DiagnosticBuilder(DiagnosticsEngine *diagObj) - : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0) { + : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(true) { assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!"); } @@ -789,10 +796,13 @@ protected: } /// \brief Clear out the current diagnostic. - void Clear() { DiagObj = 0; } + void Clear() const { + DiagObj = 0; + IsActive = false; + } /// isActive - Determine whether this diagnostic is still active. - bool isActive() const { return DiagObj != 0; } + bool isActive() const { return IsActive; } /// \brief Force the diagnostic builder to emit the diagnostic now. /// @@ -802,9 +812,9 @@ protected: /// \returns true if a diagnostic was emitted, false if the /// diagnostic was suppressed. bool Emit() { - // If DiagObj is null, then its soul was stolen by the copy ctor - // or the user called Emit(). - if (DiagObj == 0) return false; + // If this diagnostic is inactive, then its soul was stolen by the copy ctor + // (or by a subclass, as in SemaDiagnosticBuilder). + if (!isActive()) return false; // When emitting diagnostics, we set the final argument count into // the DiagnosticsEngine object. @@ -814,7 +824,7 @@ protected: bool Result = DiagObj->EmitCurrentDiagnostic(); // This diagnostic is dead. - DiagObj = 0; + Clear(); return Result; } @@ -824,7 +834,8 @@ public: /// input and neuters it. DiagnosticBuilder(const DiagnosticBuilder &D) { DiagObj = D.DiagObj; - D.DiagObj = 0; + IsActive = D.IsActive; + D.Clear(); NumArgs = D.NumArgs; NumRanges = D.NumRanges; NumFixits = D.NumFixits;