From: Alp Toker Date: Sat, 7 Dec 2013 13:51:35 +0000 (+0000) Subject: Eliminate the last trivial NDEBUG uses in clang headers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d45fce1c6346b29c4928a859fdac3d30e96f097a;p=clang Eliminate the last trivial NDEBUG uses in clang headers assert(sanity()) reads so much better than preprocessor conditional blocks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196657 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index e0d4ed1684..cf016a7555 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -319,7 +319,7 @@ protected: DeclContext *Parent, std::size_t Extra = 0); private: - void CheckAccessDeclContext() const; + bool AccessDeclContextSanity() const; protected: @@ -413,15 +413,11 @@ public: void setAccess(AccessSpecifier AS) { Access = AS; -#ifndef NDEBUG - CheckAccessDeclContext(); -#endif + assert(AccessDeclContextSanity()); } AccessSpecifier getAccess() const { -#ifndef NDEBUG - CheckAccessDeclContext(); -#endif + assert(AccessDeclContextSanity()); return AccessSpecifier(Access); } diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 197fe51e30..b5dbc1b997 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -2633,7 +2633,7 @@ public: private: Stmt *Op; - void CheckCastConsistency() const; + bool CastConsistency() const; const CXXBaseSpecifier * const *path_buffer() const { return const_cast(this)->path_buffer(); @@ -2664,9 +2664,7 @@ protected: assert(kind != CK_Invalid && "creating cast with invalid cast kind"); CastExprBits.Kind = kind; setBasePathSize(BasePathSize); -#ifndef NDEBUG - CheckCastConsistency(); -#endif + assert(CastConsistency()); } /// \brief Construct an empty cast. diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h index 105c8791e2..03643b0f2e 100644 --- a/include/clang/Sema/Lookup.h +++ b/include/clang/Sema/Lookup.h @@ -259,7 +259,7 @@ public: } LookupResultKind getResultKind() const { - sanity(); + assert(sanity()); return ResultKind; } @@ -637,13 +637,7 @@ private: void configure(); // Sanity checks. - void sanityImpl() const; - - void sanity() const { -#ifndef NDEBUG - sanityImpl(); -#endif - } + bool sanity() const; bool sanityCheckUnresolved() const { for (iterator I = begin(), E = end(); I != E; ++I) diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 7dc4493943..4eceda4fac 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -667,7 +667,7 @@ SourceLocation Decl::getBodyRBrace() const { return SourceLocation(); } -void Decl::CheckAccessDeclContext() const { +bool Decl::AccessDeclContextSanity() const { #ifndef NDEBUG // Suppress this check if any of the following hold: // 1. this is the translation unit (and thus has no parent) @@ -689,11 +689,12 @@ void Decl::CheckAccessDeclContext() const { // AS_none as access specifier. isa(this) || isa(this)) - return; + return true; assert(Access != AS_none && "Access specifier is AS_none inside a record decl"); #endif + return true; } static Decl::Kind getKind(const Decl *D) { return D->getKind(); } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index d98d0a537e..14c8452fb5 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1421,7 +1421,7 @@ SourceLocation MemberExpr::getLocEnd() const { return EndLoc; } -void CastExpr::CheckCastConsistency() const { +bool CastExpr::CastConsistency() const { switch (getCastKind()) { case CK_DerivedToBase: case CK_UncheckedDerivedToBase: @@ -1524,6 +1524,7 @@ void CastExpr::CheckCastConsistency() const { assert(path_empty() && "Cast kind should not have a base path!"); break; } + return true; } const char *CastExpr::getCastKindName() const { diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 919c6ad61a..ed2f5e93d3 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -315,7 +315,7 @@ void LookupResult::configure() { } } -void LookupResult::sanityImpl() const { +bool LookupResult::sanity() const { // Note that this function is never called by NDEBUG builds. See // LookupResult::sanity(). assert(ResultKind != NotFound || Decls.size() == 0); @@ -330,6 +330,7 @@ void LookupResult::sanityImpl() const { assert((Paths != NULL) == (ResultKind == Ambiguous && (Ambiguity == AmbiguousBaseSubobjectTypes || Ambiguity == AmbiguousBaseSubobjects))); + return true; } // Necessary because CXXBasePaths is not complete in Sema.h