1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include "mpiimpl.h"
7 #define MPIU_ASSERT_FMT_MSG_MAX_SIZE 2048
8
9
10 /* assertion helper routines
11 *
12 * These exist to de-clutter the post-processed code and reduce the chance that
13 * all of the assertion code will confuse the compiler into making bad
14 * optimization decisions. By the time one of these functions is called, the
15 * assertion has already failed and we can do more-expensive things because we
16 * are on the way out anyway. */
17
MPIR_Assert_fail(const char * cond,const char * file_name,int line_num)18 int MPIR_Assert_fail(const char *cond, const char *file_name, int line_num)
19 {
20 MPL_VG_PRINTF_BACKTRACE("Assertion failed in file %s at line %d: %s\n",
21 file_name, line_num, cond);
22 MPL_internal_error_printf("Assertion failed in file %s at line %d: %s\n",
23 file_name, line_num, cond);
24 MPL_DBG_MSG_FMT(MPIR_DBG_ASSERT, TERSE,
25 (MPL_DBG_FDEST,
26 "Assertion failed in file %s at line %d: %s", file_name, line_num, cond));
27 MPL_backtrace_show(stderr);
28 MPID_Abort(NULL, MPI_SUCCESS, 1, NULL);
29 return MPI_ERR_INTERN; /* never get here, abort should kill us */
30 }
31
MPIR_Assert_fail_fmt(const char * cond,const char * file_name,int line_num,const char * fmt,...)32 int MPIR_Assert_fail_fmt(const char *cond, const char *file_name, int line_num, const char *fmt,
33 ...)
34 {
35 char msg[MPIU_ASSERT_FMT_MSG_MAX_SIZE] = { '\0' };
36 va_list vl;
37
38 va_start(vl, fmt);
39 vsnprintf(msg, sizeof(msg), fmt, vl); /* don't check rc, can't handle it anyway */
40
41 MPL_VG_PRINTF_BACKTRACE("Assertion failed in file %s at line %d: %s\n",
42 file_name, line_num, cond);
43 MPL_VG_PRINTF_BACKTRACE("%s\n", msg);
44
45 MPL_internal_error_printf("Assertion failed in file %s at line %d: %s\n",
46 file_name, line_num, cond);
47 MPL_internal_error_printf("%s\n", msg);
48
49 MPL_DBG_MSG_FMT(MPIR_DBG_ASSERT, TERSE,
50 (MPL_DBG_FDEST,
51 "Assertion failed in file %s at line %d: %s", file_name, line_num, cond));
52 MPL_DBG_MSG_FMT(MPIR_DBG_ASSERT, TERSE, (MPL_DBG_FDEST, "%s", msg));
53
54 va_end(vl);
55
56 MPID_Abort(NULL, MPI_SUCCESS, 1, NULL);
57 return MPI_ERR_INTERN; /* never get here, abort should kill us */
58 }
59