From 5d5038723c202b04272f14abc64e7b6a0bbe2979 Mon Sep 17 00:00:00 2001 From: Morgan Deters Date: Thu, 27 Jun 2013 15:01:21 -0400 Subject: Remove macros EXPECT_TRUE / EXPECT_FALSE from cvc4_public.h so that they don't escape to user space Thanks to Alex Horn for raising the issue on the CVC-BUGS mailing list. --- src/expr/node.h | 4 ++-- src/expr/node_builder.h | 34 +++++++++++++++++----------------- src/expr/node_value.h | 10 +++++----- src/expr/type_node.cpp | 2 +- src/expr/type_node.h | 2 +- src/include/cvc4_public.h | 3 --- src/parser/bounded_token_buffer.cpp | 2 +- src/util/cvc4_assert.cpp | 2 +- src/util/cvc4_assert.h | 14 +++++++------- src/util/debug.h | 4 ++-- src/util/exception.h | 8 ++++---- 11 files changed, 41 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/expr/node.h b/src/expr/node.h index 7003aae87..d9e88d8af 100644 --- a/src/expr/node.h +++ b/src/expr/node.h @@ -1094,7 +1094,7 @@ NodeTemplate& NodeTemplate:: operator=(const NodeTemplate& e) { Assert(d_nv != NULL, "Expecting a non-NULL expression value!"); Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!"); - if(EXPECT_TRUE( d_nv != e.d_nv )) { + if(__builtin_expect( ( d_nv != e.d_nv ), true )) { if(ref_count) { // shouldn't ever fail Assert(d_nv->d_rc > 0, @@ -1118,7 +1118,7 @@ NodeTemplate& NodeTemplate:: operator=(const NodeTemplate& e) { Assert(d_nv != NULL, "Expecting a non-NULL expression value!"); Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!"); - if(EXPECT_TRUE( d_nv != e.d_nv )) { + if(__builtin_expect( ( d_nv != e.d_nv ), true )) { if(ref_count) { // shouldn't ever fail Assert(d_nv->d_rc > 0, "Node reference count would be negative"); diff --git a/src/expr/node_builder.h b/src/expr/node_builder.h index 773828ccb..1f098b4e8 100644 --- a/src/expr/node_builder.h +++ b/src/expr/node_builder.h @@ -228,7 +228,7 @@ class NodeBuilder { * Internally, this state is represented by d_nv pointing to NULL. */ inline bool isUsed() const { - return EXPECT_FALSE( d_nv == NULL ); + return __builtin_expect( ( d_nv == NULL ), false ); } /** @@ -259,7 +259,7 @@ class NodeBuilder { * heap-allocated by this class). */ inline bool nvIsAllocated() const { - return EXPECT_FALSE( d_nv != &d_inlineNv ) && EXPECT_TRUE( d_nv != NULL ); + return __builtin_expect( ( d_nv != &d_inlineNv ), false ) && __builtin_expect(( d_nv != NULL ), true ); } /** @@ -267,7 +267,7 @@ class NodeBuilder { * first. */ inline bool nvNeedsToBeAllocated() const { - return EXPECT_FALSE( d_nv->d_nchildren == d_nvMaxChildren ); + return __builtin_expect( ( d_nv->d_nchildren == d_nvMaxChildren ), false ); } /** @@ -279,7 +279,7 @@ class NodeBuilder { inline void realloc() { size_t newSize = 2 * size_t(d_nvMaxChildren); size_t hardLimit = (1lu << __CVC4__EXPR__NODE_VALUE__NBITS__NCHILDREN) - 1; - realloc(EXPECT_FALSE( newSize > hardLimit ) ? hardLimit : newSize); + realloc(__builtin_expect( ( newSize > hardLimit ), false ) ? hardLimit : newSize); } /** @@ -297,7 +297,7 @@ class NodeBuilder { * double-decremented on destruction/clear. Otherwise, do nothing. */ inline void allocateNvIfNecessaryForAppend() { - if(EXPECT_FALSE( nvNeedsToBeAllocated() )) { + if(__builtin_expect( ( nvNeedsToBeAllocated() ), false )) { realloc(); } } @@ -331,8 +331,8 @@ class NodeBuilder { * @throws bad_alloc if the reallocation fails */ void crop() { - if(EXPECT_FALSE( nvIsAllocated() ) && - EXPECT_TRUE( d_nvMaxChildren > d_nv->d_nchildren )) { + if(__builtin_expect( ( nvIsAllocated() ), false ) && + __builtin_expect( ( d_nvMaxChildren > d_nv->d_nchildren ), true )) { // Ensure d_nv is not modified on allocation failure expr::NodeValue* newBlock = (expr::NodeValue*) std::realloc(d_nv, @@ -419,9 +419,9 @@ public: } inline ~NodeBuilder() { - if(EXPECT_FALSE( nvIsAllocated() )) { + if(__builtin_expect( ( nvIsAllocated() ), false )) { dealloc(); - } else if(EXPECT_FALSE( !isUsed() )) { + } else if(__builtin_expect( ( !isUsed() ), false )) { decrRefCounts(); } } @@ -578,7 +578,7 @@ public: // NodeBuilder construction or at the last clear()), but we do // now. That means we appended a Kind with operator<<(Kind), // which now (lazily) we'll collapse. - if(EXPECT_FALSE( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND )) { + if(__builtin_expect( ( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND ), false )) { Node n2 = operator Node(); clear(); append(n2); @@ -600,7 +600,7 @@ public: // NodeBuilder construction or at the last clear()), but we do // now. That means we appended a Kind with operator<<(Kind), // which now (lazily) we'll collapse. - if(EXPECT_FALSE( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND )) { + if(__builtin_expect( ( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND ), false )) { Node n2 = operator Node(); clear(); append(n2); @@ -619,7 +619,7 @@ public: // NodeBuilder construction or at the last clear()), but we do // now. That means we appended a Kind with operator<<(Kind), // which now (lazily) we'll collapse. - if(EXPECT_FALSE( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND )) { + if(__builtin_expect( ( d_nv->d_id == 0 && getKind() != kind::UNDEFINED_KIND ), false )) { Node n2 = operator Node(); clear(); append(n2); @@ -756,9 +756,9 @@ template void NodeBuilder::clear(Kind k) { Assert(k != kind::NULL_EXPR, "illegal Node-building clear kind"); - if(EXPECT_FALSE( nvIsAllocated() )) { + if(__builtin_expect( ( nvIsAllocated() ), false )) { dealloc(); - } else if(EXPECT_FALSE( !isUsed() )) { + } else if(__builtin_expect( ( !isUsed() ), false )) { decrRefCounts(); } else { setUnused(); @@ -783,7 +783,7 @@ void NodeBuilder::realloc(size_t toSize) { "attempt to realloc() a NodeBuilder to size %u (beyond hard limit of %u)", toSize, (1lu << __CVC4__EXPR__NODE_VALUE__NBITS__NCHILDREN) - 1 ); - if(EXPECT_FALSE( nvIsAllocated() )) { + if(__builtin_expect( ( nvIsAllocated() ), false )) { // Ensure d_nv is not modified on allocation failure expr::NodeValue* newBlock = (expr::NodeValue*) std::realloc(d_nv, sizeof(expr::NodeValue) + @@ -992,7 +992,7 @@ expr::NodeValue* NodeBuilder::constructNV() { // NodeManager pool of Nodes. See implementation notes at the top // of this file. - if(EXPECT_TRUE( ! nvIsAllocated() )) { + if(__builtin_expect( ( ! nvIsAllocated() ), true )) { /** Case 1. d_nv points to d_inlineNv: it is the backing store ** allocated "inline" in this NodeBuilder. **/ @@ -1177,7 +1177,7 @@ expr::NodeValue* NodeBuilder::constructNV() const { // NodeManager pool of Nodes. See implementation notes at the top // of this file. - if(EXPECT_TRUE( ! nvIsAllocated() )) { + if(__builtin_expect( ( ! nvIsAllocated() ), true )) { /** Case 1. d_nv points to d_inlineNv: it is the backing store ** allocated "inline" in this NodeBuilder. **/ diff --git a/src/expr/node_value.h b/src/expr/node_value.h index 13fdc6a7f..56ac70c1e 100644 --- a/src/expr/node_value.h +++ b/src/expr/node_value.h @@ -299,7 +299,7 @@ private: RefCountGuard(const NodeValue* nv) : d_nv(const_cast(nv)) { // inc() - if(EXPECT_TRUE( d_nv->d_rc < MAX_RC )) { + if(__builtin_expect( ( d_nv->d_rc < MAX_RC ), true )) { ++d_nv->d_rc; } } @@ -309,7 +309,7 @@ private: // E.g., this can happen when debugging code calls the print // routines below. As RefCountGuards are scoped on the stack, // this should be fine---but not in multithreaded contexts! - if(EXPECT_TRUE( d_nv->d_rc < MAX_RC )) { + if(__builtin_expect( ( d_nv->d_rc < MAX_RC ), true )) { --d_nv->d_rc; } } @@ -400,16 +400,16 @@ inline void NodeValue::inc() { "NodeValue is currently being deleted " "and increment is being called on it. Don't Do That!"); // FIXME multithreading - if(EXPECT_TRUE( d_rc < MAX_RC )) { + if(__builtin_expect( ( d_rc < MAX_RC ), true )) { ++d_rc; } } inline void NodeValue::dec() { // FIXME multithreading - if(EXPECT_TRUE( d_rc < MAX_RC )) { + if(__builtin_expect( ( d_rc < MAX_RC ), true )) { --d_rc; - if(EXPECT_FALSE( d_rc == 0 )) { + if(__builtin_expect( ( d_rc == 0 ), false )) { Assert(NodeManager::currentNM() != NULL, "No current NodeManager on destruction of NodeValue: " "maybe a public CVC4 interface function is missing a NodeManagerScope ?"); diff --git a/src/expr/type_node.cpp b/src/expr/type_node.cpp index 1d4c330fa..2fc380224 100644 --- a/src/expr/type_node.cpp +++ b/src/expr/type_node.cpp @@ -300,7 +300,7 @@ TypeNode TypeNode::leastCommonTypeNode(TypeNode t0, TypeNode t1){ Assert(!t0.isNull()); Assert(!t1.isNull()); - if(EXPECT_TRUE(t0 == t1)) { + if(__builtin_expect( (t0 == t1), true )) { return t0; } else { // t0 != t1 if(t0.getKind()== kind::TYPE_CONSTANT) { diff --git a/src/expr/type_node.h b/src/expr/type_node.h index 35d630a91..061e73fc9 100644 --- a/src/expr/type_node.h +++ b/src/expr/type_node.h @@ -770,7 +770,7 @@ inline TypeNode& TypeNode::operator=(const TypeNode& typeNode) { Assert(d_nv != NULL, "Expecting a non-NULL expression value!"); Assert(typeNode.d_nv != NULL, "Expecting a non-NULL expression value on RHS!"); - if(EXPECT_TRUE( d_nv != typeNode.d_nv )) { + if(__builtin_expect( ( d_nv != typeNode.d_nv ), true )) { d_nv->dec(); d_nv = typeNode.d_nv; d_nv->inc(); diff --git a/src/include/cvc4_public.h b/src/include/cvc4_public.h index b8c30aeef..b7431ce1c 100644 --- a/src/include/cvc4_public.h +++ b/src/include/cvc4_public.h @@ -68,7 +68,4 @@ # define CVC4_WARN_UNUSED_RESULT #endif /* __GNUC__ */ -#define EXPECT_TRUE(x) __builtin_expect( (x), true ) -#define EXPECT_FALSE(x) __builtin_expect( (x), false ) - #endif /* __CVC4_PUBLIC_H */ diff --git a/src/parser/bounded_token_buffer.cpp b/src/parser/bounded_token_buffer.cpp index 88a7c6463..112d9b0ed 100644 --- a/src/parser/bounded_token_buffer.cpp +++ b/src/parser/bounded_token_buffer.cpp @@ -241,7 +241,7 @@ static pANTLR3_COMMON_TOKEN tokLT(pANTLR3_TOKEN_STREAM ts, ANTLR3_INT32 k) { } /* Initialize the buffer on our first call. */ - if( EXPECT_FALSE(buffer->empty == ANTLR3_TRUE) ) { + if( __builtin_expect( (buffer->empty == ANTLR3_TRUE), false ) ) { assert( buffer->tokenBuffer != NULL ); buffer->tokenBuffer[ 0 ] = nextToken(buffer); buffer->maxIndex = 0; diff --git a/src/util/cvc4_assert.cpp b/src/util/cvc4_assert.cpp index eb7b81a39..08e2867f6 100644 --- a/src/util/cvc4_assert.cpp +++ b/src/util/cvc4_assert.cpp @@ -136,7 +136,7 @@ void debugAssertionFailed(const AssertionException& thisException, const char* propagatingException) { static CVC4_THREADLOCAL(bool) alreadyFired = false; - if(EXPECT_TRUE( !std::uncaught_exception() ) || alreadyFired) { + if(__builtin_expect( ( !std::uncaught_exception() ), true ) || alreadyFired) { throw thisException; } diff --git a/src/util/cvc4_assert.h b/src/util/cvc4_assert.h index c070fc389..7d359a56b 100644 --- a/src/util/cvc4_assert.h +++ b/src/util/cvc4_assert.h @@ -252,7 +252,7 @@ void debugAssertionFailed(const AssertionException& thisException, const char* l // details of the exception # define AlwaysAssert(cond, msg...) \ do { \ - if(EXPECT_FALSE( ! (cond) )) { \ + if(__builtin_expect( ( ! (cond) ), false )) { \ /* save the last assertion failure */ \ const char* lastException = ::CVC4::s_debugLastException; \ ::CVC4::AssertionException exception(#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \ @@ -265,7 +265,7 @@ void debugAssertionFailed(const AssertionException& thisException, const char* l // will terminate() if thrown during stack unwinding. # define AlwaysAssert(cond, msg...) \ do { \ - if(EXPECT_FALSE( ! (cond) )) { \ + if(__builtin_expect( ( ! (cond) ), false )) { \ throw ::CVC4::AssertionException(#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \ } \ } while(0) @@ -283,13 +283,13 @@ void debugAssertionFailed(const AssertionException& thisException, const char* l throw ::CVC4::IllegalArgumentException("", #arg, __PRETTY_FUNCTION__, ## msg) #define CheckArgument(cond, arg, msg...) \ do { \ - if(EXPECT_FALSE( ! (cond) )) { \ + if(__builtin_expect( ( ! (cond) ), false )) { \ throw ::CVC4::IllegalArgumentException(#cond, #arg, __PRETTY_FUNCTION__, ## msg); \ } \ } while(0) #define AlwaysAssertArgument(cond, arg, msg...) \ do { \ - if(EXPECT_FALSE( ! (cond) )) { \ + if(__builtin_expect( ( ! (cond) ), false )) { \ throw ::CVC4::AssertArgumentException(#cond, #arg, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## msg); \ } \ } while(0) @@ -299,9 +299,9 @@ void debugAssertionFailed(const AssertionException& thisException, const char* l # define AssertArgument(cond, arg, msg...) AlwaysAssertArgument(cond, arg, ## msg) # define DebugCheckArgument(cond, arg, msg...) CheckArgument(cond, arg, ## msg) #else /* ! CVC4_ASSERTIONS */ -# define Assert(cond, msg...) /*EXPECT_TRUE( cond )*/ -# define AssertArgument(cond, arg, msg...) /*EXPECT_TRUE( cond )*/ -# define DebugCheckArgument(cond, arg, msg...) /*EXPECT_TRUE( cond )*/ +# define Assert(cond, msg...) /*__builtin_expect( ( cond ), true )*/ +# define AssertArgument(cond, arg, msg...) /*__builtin_expect( ( cond ), true )*/ +# define DebugCheckArgument(cond, arg, msg...) /*__builtin_expect( ( cond ), true )*/ #endif /* CVC4_ASSERTIONS */ }/* CVC4 namespace */ diff --git a/src/util/debug.h b/src/util/debug.h index 3e7c4d8be..97c176f02 100644 --- a/src/util/debug.h +++ b/src/util/debug.h @@ -27,11 +27,11 @@ #ifdef CVC4_ASSERTIONS // the __builtin_expect() helps us if assert is built-in or a macro -# define cvc4assert(x) assert(EXPECT_TRUE( x )) +# define cvc4assert(x) assert(__builtin_expect( ( x ), true )) #else // TODO: use a compiler annotation when assertions are off ? // (to improve optimization) -# define cvc4assert(x) /*EXPECT_TRUE( x )*/ +# define cvc4assert(x) /*__builtin_expect( ( x ), true )*/ #endif /* CVC4_ASSERTIONS */ #endif /* __CVC4__DEBUG_H */ diff --git a/src/util/exception.h b/src/util/exception.h index 082a50ef2..cd4b763ef 100644 --- a/src/util/exception.h +++ b/src/util/exception.h @@ -138,13 +138,13 @@ namespace CVC4 { #ifndef CheckArgument template inline void CheckArgument(bool cond, const T& arg, const char* fmt, ...) CVC4_PUBLIC; template inline void CheckArgument(bool cond, const T& arg, const char* fmt, ...) { - if(EXPECT_FALSE( !cond )) { \ + if(__builtin_expect( ( !cond ), false )) { \ throw ::CVC4::IllegalArgumentException("", "", ""); \ } \ } template inline void CheckArgument(bool cond, const T& arg) CVC4_PUBLIC; template inline void CheckArgument(bool cond, const T& arg) { - if(EXPECT_FALSE( !cond )) { \ + if(__builtin_expect( ( !cond ), false )) { \ throw ::CVC4::IllegalArgumentException("", "", ""); \ } \ } @@ -153,13 +153,13 @@ template inline void CheckArgument(bool cond, const T& arg) { #ifndef DebugCheckArgument template inline void DebugCheckArgument(bool cond, const T& arg, const char* fmt, ...) CVC4_PUBLIC; template inline void DebugCheckArgument(bool cond, const T& arg, const char* fmt, ...) { - if(EXPECT_FALSE( !cond )) { \ + if(__builtin_expect( ( !cond ), false )) { \ throw ::CVC4::IllegalArgumentException("", "", ""); \ } \ } template inline void DebugCheckArgument(bool cond, const T& arg) CVC4_PUBLIC; template inline void DebugCheckArgument(bool cond, const T& arg) { - if(EXPECT_FALSE( !cond )) { \ + if(__builtin_expect( ( !cond ), false )) { \ throw ::CVC4::IllegalArgumentException("", "", ""); \ } \ } -- cgit v1.2.3