Author: d0k Date: Wed Jan 18 09:50:26 2017 New Revision: 292402 URL: http://llvm.org/viewvc/llvm-project?rev=292402&view=rev Log: [Basic] Remove source manager references from diag state points.
This is just wasted space, we don't support state points from multiple source managers. Validate that there's no state when resetting the source manager and use the 'global' reference to the sourcemanager instead of the ones in the diag state. Modified: cfe/trunk/include/clang/Basic/Diagnostic.h cfe/trunk/lib/Basic/Diagnostic.cpp Modified: cfe/trunk/include/clang/Basic/Diagnostic.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=292402&r1=292401&r2=292402&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/Diagnostic.h (original) +++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Jan 18 09:50:26 2017 @@ -239,19 +239,9 @@ private: /// modifications done through the command-line. struct DiagStatePoint { DiagState *State; - FullSourceLoc Loc; - DiagStatePoint(DiagState *State, FullSourceLoc Loc) + SourceLocation Loc; + DiagStatePoint(DiagState *State, SourceLocation Loc) : State(State), Loc(Loc) { } - - bool operator<(const DiagStatePoint &RHS) const { - // If Loc is invalid it means it came from <command-line>, in which case - // we regard it as coming before any valid source location. - if (RHS.Loc.isInvalid()) - return false; - if (Loc.isInvalid()) - return true; - return Loc.isBeforeInTranslationUnitThan(RHS.Loc); - } }; /// \brief A sorted vector of all DiagStatePoints representing changes in @@ -271,16 +261,7 @@ private: return DiagStatePoints.back().State; } - void PushDiagStatePoint(DiagState *State, SourceLocation L) { - FullSourceLoc Loc(L, getSourceManager()); - // Make sure that DiagStatePoints is always sorted according to Loc. - assert(Loc.isValid() && "Adding invalid loc point"); - assert(!DiagStatePoints.empty() && - (DiagStatePoints.back().Loc.isInvalid() || - DiagStatePoints.back().Loc.isBeforeInTranslationUnitThan(Loc)) && - "Previous point loc comes after or is the same as new one"); - DiagStatePoints.push_back(DiagStatePoint(State, Loc)); - } + void PushDiagStatePoint(DiagState *State, SourceLocation L); /// \brief Finds the DiagStatePoint that contains the diagnostic state of /// the given source location. @@ -390,7 +371,11 @@ public: assert(SourceMgr && "SourceManager not set!"); return *SourceMgr; } - void setSourceManager(SourceManager *SrcMgr) { SourceMgr = SrcMgr; } + void setSourceManager(SourceManager *SrcMgr) { + assert(DiagStatePoints.size() == 1 && DiagStatePoints[0].Loc.isInvalid() && + "Leftover diag state from a different SourceManager."); + SourceMgr = SrcMgr; + } //===--------------------------------------------------------------------===// // DiagnosticsEngine characterization methods, used by a client to customize Modified: cfe/trunk/lib/Basic/Diagnostic.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=292402&r1=292401&r2=292402&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Diagnostic.cpp (original) +++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Jan 18 09:50:26 2017 @@ -16,6 +16,7 @@ #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/PartialDiagnostic.h" +#include "clang/Basic/SourceManager.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CrashRecoveryContext.h" @@ -137,7 +138,7 @@ void DiagnosticsEngine::Reset() { // Create a DiagState and DiagStatePoint representing diagnostic changes // through command-line. DiagStates.emplace_back(); - DiagStatePoints.push_back(DiagStatePoint(&DiagStates.back(), FullSourceLoc())); + DiagStatePoints.emplace_back(&DiagStates.back(), SourceLocation()); } void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1, @@ -157,6 +158,18 @@ void DiagnosticsEngine::ReportDelayed() DelayedDiagArg2.clear(); } +void DiagnosticsEngine::PushDiagStatePoint(DiagState *State, + SourceLocation Loc) { + // Make sure that DiagStatePoints is always sorted according to Loc. + assert(Loc.isValid() && "Adding invalid loc point"); + assert(!DiagStatePoints.empty() && + (DiagStatePoints.back().Loc.isInvalid() || + getSourceManager().isBeforeInTranslationUnit( + DiagStatePoints.back().Loc, Loc)) && + "Previous point loc comes after or is the same as new one"); + DiagStatePoints.push_back(DiagStatePoint(State, Loc)); +} + DiagnosticsEngine::DiagStatePointsTy::iterator DiagnosticsEngine::GetDiagStatePointForLoc(SourceLocation L) const { assert(!DiagStatePoints.empty()); @@ -171,11 +184,21 @@ DiagnosticsEngine::GetDiagStatePointForL return DiagStatePoints.end() - 1; DiagStatePointsTy::iterator Pos = DiagStatePoints.end(); - FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc; + SourceLocation LastStateChangePos = DiagStatePoints.back().Loc; if (LastStateChangePos.isValid() && Loc.isBeforeInTranslationUnitThan(LastStateChangePos)) - Pos = std::upper_bound(DiagStatePoints.begin(), DiagStatePoints.end(), - DiagStatePoint(nullptr, Loc)); + Pos = std::upper_bound( + DiagStatePoints.begin(), DiagStatePoints.end(), + DiagStatePoint(nullptr, Loc), + [this](const DiagStatePoint &LHS, const DiagStatePoint &RHS) { + // If Loc is invalid it means it came from <command-line>, in which + // case we regard it as coming before any valid source location. + if (RHS.Loc.isInvalid()) + return false; + if (LHS.Loc.isInvalid()) + return true; + return SourceMgr->isBeforeInTranslationUnit(LHS.Loc, RHS.Loc); + }); --Pos; return Pos; } @@ -190,8 +213,8 @@ void DiagnosticsEngine::setSeverity(diag assert(!DiagStatePoints.empty()); assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location"); - FullSourceLoc Loc = SourceMgr? FullSourceLoc(L, *SourceMgr) : FullSourceLoc(); - FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc; + SourceLocation Loc = SourceMgr ? L : SourceLocation(); + SourceLocation LastStateChangePos = DiagStatePoints.back().Loc; // Don't allow a mapping to a warning override an error/fatal mapping. if (Map == diag::Severity::Warning) { DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); @@ -210,7 +233,7 @@ void DiagnosticsEngine::setSeverity(diag // Another common case; modifying diagnostic state in a source location // after the previous one. if ((Loc.isValid() && LastStateChangePos.isInvalid()) || - LastStateChangePos.isBeforeInTranslationUnitThan(Loc)) { + SourceMgr->isBeforeInTranslationUnit(LastStateChangePos, Loc)) { // A diagnostic pragma occurred, create a new DiagState initialized with // the current one and a new DiagStatePoint to record at which location // the new state became active. @@ -240,12 +263,11 @@ void DiagnosticsEngine::setSeverity(diag // Create a new state/point and fit it into the vector of DiagStatePoints // so that the vector is always ordered according to location. - assert(Pos->Loc.isBeforeInTranslationUnitThan(Loc)); + assert(SourceMgr->isBeforeInTranslationUnit(Pos->Loc, Loc)); DiagStates.push_back(*Pos->State); DiagState *NewState = &DiagStates.back(); NewState->setMapping(Diag, Mapping); - DiagStatePoints.insert(Pos+1, DiagStatePoint(NewState, - FullSourceLoc(Loc, *SourceMgr))); + DiagStatePoints.insert(Pos + 1, DiagStatePoint(NewState, Loc)); } bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits