|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifndef MPIR_ASSERT_H_INCLUDED
|
|
Packit Service |
c5cf8c |
#define MPIR_ASSERT_H_INCLUDED
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpir_type_defs.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* modern versions of clang support lots of C11 features */
|
|
Packit Service |
c5cf8c |
#if defined(__has_extension)
|
|
Packit Service |
c5cf8c |
#if __has_extension(c_generic_selections)
|
|
Packit Service |
c5cf8c |
#define HAVE_C11__GENERIC 1
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#if __has_extension(c_static_assert)
|
|
Packit Service |
c5cf8c |
#define HAVE_C11__STATIC_ASSERT 1
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* GCC 4.6 added support for _Static_assert:
|
|
Packit Service |
c5cf8c |
* http://gcc.gnu.org/gcc-4.6/changes.html */
|
|
Packit Service |
c5cf8c |
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined __cplusplus
|
|
Packit Service |
c5cf8c |
#define HAVE_C11__STATIC_ASSERT 1
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* prototypes for assertion implementation helpers */
|
|
Packit Service |
c5cf8c |
int MPIR_Assert_fail(const char *cond, const char *file_name, int line_num);
|
|
Packit Service |
c5cf8c |
int MPIR_Assert_fail_fmt(const char *cond, const char *file_name, int line_num, const char *fmt,
|
|
Packit Service |
c5cf8c |
...);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* MPIR_Assert()
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Similar to assert() except that it performs an MPID_Abort() when the
|
|
Packit Service |
c5cf8c |
* assertion fails. Also, for Windows, it doesn't popup a
|
|
Packit Service |
c5cf8c |
* mesage box on a remote machine.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#if (defined(__COVERITY__) || defined(__KLOCWORK__))
|
|
Packit Service |
c5cf8c |
#include <assert.h>
|
|
Packit Service |
c5cf8c |
#define MPIR_Assert(a_) assert(a_);
|
|
Packit Service |
c5cf8c |
#elif (!defined(NDEBUG) && defined(HAVE_ERROR_CHECKING))
|
|
Packit Service |
c5cf8c |
#define MPIR_AssertDeclValue(_a,_b) _a = _b
|
|
Packit Service |
c5cf8c |
#define MPIR_Assert(a_) \
|
|
Packit Service |
c5cf8c |
do { \
|
|
Packit Service |
c5cf8c |
if (unlikely(!(a_))) { \
|
|
Packit Service |
c5cf8c |
MPIR_Assert_fail(#a_, __FILE__, __LINE__); \
|
|
Packit Service |
c5cf8c |
} \
|
|
Packit Service |
c5cf8c |
} while (0)
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define MPIR_Assert(a_)
|
|
Packit Service |
c5cf8c |
/* Empty decls not allowed in C */
|
|
Packit Service |
c5cf8c |
#define MPIR_AssertDeclValue(_a,_b) _a ATTRIBUTE((unused)) = _b
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* MPIR_Assertp()
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Similar to MPIR_Assert() except that these assertions persist regardless of
|
|
Packit Service |
c5cf8c |
* NDEBUG or HAVE_ERROR_CHECKING. MPIR_Assertp() may
|
|
Packit Service |
c5cf8c |
* be used for error checking in prototype code, although it should be
|
|
Packit Service |
c5cf8c |
* converted real error checking and reporting once the
|
|
Packit Service |
c5cf8c |
* prototype becomes part of the official and supported code base.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#define MPIR_Assertp(a_) \
|
|
Packit Service |
c5cf8c |
do { \
|
|
Packit Service |
c5cf8c |
if (unlikely(!(a_))) { \
|
|
Packit Service |
c5cf8c |
MPIR_Assert_fail(#a_, __FILE__, __LINE__); \
|
|
Packit Service |
c5cf8c |
} \
|
|
Packit Service |
c5cf8c |
} while (0)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Define the MPIR_Assert_fmt_msg macro. This macro takes two arguments. The
|
|
Packit Service |
c5cf8c |
* first is the condition to assert. The second is a parenthesized list of
|
|
Packit Service |
c5cf8c |
* arguments suitable for passing directly to printf that will yield a relevant
|
|
Packit Service |
c5cf8c |
* error message. The macro will first evaluate the condition. If it evaluates
|
|
Packit Service |
c5cf8c |
* to false the macro will take four steps:
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* 1) It will emit an "Assertion failed..." message in the valgrind output with
|
|
Packit Service |
c5cf8c |
* a backtrace, if valgrind client requests are available and the process is
|
|
Packit Service |
c5cf8c |
* running under valgrind. It will also evaluate and print the supplied
|
|
Packit Service |
c5cf8c |
* message.
|
|
Packit Service |
c5cf8c |
* 2) It will emit an "Assertion failed..." message via MPL_internal_error_printf.
|
|
Packit Service |
c5cf8c |
* The supplied error message will also be evaluated and printed.
|
|
Packit Service |
c5cf8c |
* 3) It will similarly emit the assertion failure and caller supplied messages
|
|
Packit Service |
c5cf8c |
* to the debug log, if enabled, via MPL_DBG_MSG_FMT.
|
|
Packit Service |
c5cf8c |
* 4) It will invoke MPID_Abort, just like the other MPIR_Assert* macros.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* If the compiler doesn't support (...)/__VA_ARGS__ in macros then the user
|
|
Packit Service |
c5cf8c |
* message will not be evaluated or printed. If NDEBUG is defined or
|
|
Packit Service |
c5cf8c |
* HAVE_ERROR_CHECKING is undefined, this macro will expand to nothing, just
|
|
Packit Service |
c5cf8c |
* like MPIR_Assert.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Example usage:
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* MPIR_Assert_fmg_msg(foo > bar,("foo is larger than bar: foo=%d bar=%d",foo,bar));
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#if (!defined(NDEBUG) && defined(HAVE_ERROR_CHECKING))
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_MACRO_VA_ARGS)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* newlines are added internally by the impl function, callers do not need to include them */
|
|
Packit Service |
c5cf8c |
#define MPIR_Assert_fmt_msg(cond_,fmt_arg_parens_) \
|
|
Packit Service |
c5cf8c |
do { \
|
|
Packit Service |
c5cf8c |
if (unlikely(!(cond_))) { \
|
|
Packit Service |
c5cf8c |
MPIR_Assert_fail_fmt(#cond_, __FILE__, __LINE__, \
|
|
Packit Service |
c5cf8c |
fmt_msg_expand_ fmt_arg_parens_); \
|
|
Packit Service |
c5cf8c |
} \
|
|
Packit Service |
c5cf8c |
} while (0)
|
|
Packit Service |
c5cf8c |
/* helper to just expand the parens arg inline */
|
|
Packit Service |
c5cf8c |
#define fmt_msg_expand_(...) __VA_ARGS__
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#else /* defined(HAVE_MACRO_VA_ARGS) */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPIR_Assert_fmt_msg(cond_,fmt_arg_parens_) \
|
|
Packit Service |
c5cf8c |
do { \
|
|
Packit Service |
c5cf8c |
if (unlikely(!(cond_))) { \
|
|
Packit Service |
c5cf8c |
MPIR_Assert_fail_fmt(#cond_, __FILE__, __LINE__, \
|
|
Packit Service |
c5cf8c |
"%s", "macro __VA_ARGS__ not supported, unable to print user message"); \
|
|
Packit Service |
c5cf8c |
} \
|
|
Packit Service |
c5cf8c |
} while (0)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#else /* !defined(NDEBUG) && defined(HAVE_ERROR_CHECKING) */
|
|
Packit Service |
c5cf8c |
#define MPIR_Assert_fmt_msg(cond_,fmt_arg_parens_)
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_C11__STATIC_ASSERT
|
|
Packit Service |
c5cf8c |
#define MPIR_Static_assert(cond_,msg_) _Static_assert(cond_,msg_)
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
/* fallthrough to a run-time assertion */
|
|
Packit Service |
c5cf8c |
#ifndef MPIR_Static_assert
|
|
Packit Service |
c5cf8c |
#define MPIR_Static_assert(cond_,msg_) MPIR_Assert_fmt_msg((cond_), ("%s", (msg_)))
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif /* MPIR_ASSERT_H_INCLUDED */
|