[cfe-commits] r152709 - /cfe/trunk/include/clang/Basic/Diagnostic.h
Daniel Dunbar
daniel at zuster.org
Wed Mar 14 02:49:36 PDT 2012
Author: ddunbar
Date: Wed Mar 14 04:49:36 2012
New Revision: 152709
URL: http://llvm.org/viewvc/llvm-project?rev=152709&view=rev
Log:
[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.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=152709&r1=152708&r2=152709&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Mar 14 04:49:36 2012
@@ -772,10 +772,17 @@
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 @@
}
/// \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 @@
/// \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 @@
bool Result = DiagObj->EmitCurrentDiagnostic();
// This diagnostic is dead.
- DiagObj = 0;
+ Clear();
return Result;
}
@@ -824,7 +834,8 @@
/// 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;
More information about the cfe-commits
mailing list