[mpich-commits] [mpich] MPICH primary repository branch, master, updated. v3.0.4-124-gf7b6f82
mysql vizuser
noreply at mpich.org
Fri May 3 14:19:43 CDT 2013
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "MPICH primary repository".
The branch, master has been updated
via f7b6f82ac880ff0bd8f418e2c97c381947d3aa4a (commit)
via 10ecd01bc7f3c233ba16ee654e072fac114d4b63 (commit)
via 0d3c7a5cb0d28571008e0a415d392a88e7ce3388 (commit)
via da86da32172780e676261e1938b4e016772a6be3 (commit)
via 4cbc2d55371a92adf71e3e9253662f287e28f438 (commit)
via 305d986aadad4e71f59499da35f3cec4fd217595 (commit)
from 9fced770486b15aa39e40b54ab6b81c773938be1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.mpich.org/mpich.git/commitdiff/f7b6f82ac880ff0bd8f418e2c97c381947d3aa4a
commit f7b6f82ac880ff0bd8f418e2c97c381947d3aa4a
Merge: 9fced77 10ecd01
Author: Dave Goodell <goodell at mcs.anl.gov>
Date: Fri May 3 14:18:36 2013 -0500
Merge branch 'better-large-count' (early part)
This doesn't actually fix any large count issues, it just provides some
useful infrastructure for fixing them in the future.
http://git.mpich.org/mpich.git/commitdiff/10ecd01bc7f3c233ba16ee654e072fac114d4b63
commit 10ecd01bc7f3c233ba16ee654e072fac114d4b63
Author: Dave Goodell <goodell at mcs.anl.gov>
Date: Mon Mar 18 15:51:17 2013 -0500
add `MPIU_Assign_trunc` macro
This macro performs assignment, checking that the source value can be
safely expressed in the destination type without truncation. The robust
version requires C11 `_Generic`, though a weaker fallback is present.
Reviewed-by: dinan
diff --git a/src/include/mpiutil.h b/src/include/mpiutil.h
index ffb5c19..0e0dfaa 100644
--- a/src/include/mpiutil.h
+++ b/src/include/mpiutil.h
@@ -180,6 +180,59 @@ int MPIR_Assert_fail_fmt(const char *cond, const char *file_name, int line_num,
("overflow detected: (%llx * %llx) > %s", (a_), (b_), #max_)); \
+/* Helper macros that give us a crude version of C++'s
+ * "std::numeric_limits<TYPE>" functionality. These rely on either C11
+ * "_Generic" functionality or some unfortunately complicated GCC builtins. */
+#if HAVE_C11__GENERIC
+#define expr_inttype_max(expr_) \
+ _Generic(expr_, \
+ signed char: SCHAR_MAX, \
+ signed short: SHRT_MAX, \
+ signed int: INT_MAX, \
+ signed long: LONG_MAX, \
+ signed long long: LLONG_MAX, \
+ unsigned char: UCHAR_MAX, \
+ unsigned short: USHRT_MAX, \
+ unsigned int: UINT_MAX, \
+ unsigned long: ULONG_MAX, \
+ unsigned long long: ULLONG_MAX)
+#define expr_inttype_min(expr_) \
+ _Generic(expr_, \
+ signed char: SCHAR_MIN, \
+ signed short: SHRT_MIN, \
+ signed int: INT_MIN, \
+ signed long: LONG_MIN, \
+ signed long long: LLONG_MIN, \
+ unsigned char: 0, \
+ unsigned short: 0, \
+ unsigned int: 0, \
+ unsigned long: 0, \
+ unsigned long long: 0)
+#endif
+
+/* Assigns (src_) to (dst_), checking that (src_) fits in (dst_) without
+ * truncation.
+ *
+ * When fiddling with this macro, please keep C's overly complicated integer
+ * promotion/truncation/conversion rules in mind. A discussion of these issues
+ * can be found in Chapter 5 of "Secure Coding in C and C++" by Robert Seacord.
+ */
+#if defined(expr_inttype_max) && defined(expr_inttype_min)
+# define MPIU_Assign_trunc(dst_,src_) \
+ do { \
+ MPIU_Assert((src_) <= expr_inttype_max(dst_)); \
+ MPIU_Assert((src_) >= expr_inttype_min(dst_)); \
+ dst_ = (src_); \
+ } while (0)
+#else
+# define MPIU_Assign_trunc(dst_,src_) \
+ do { \
+ dst_ = (src_); \
+ /* will catch some of the cases if the expr_inttype macros aren't available */ \
+ MPIU_Assert((dst_) == (src_)); \
+ } while (0)
+#endif
+
/*
* Ensure an MPI_Aint value fits into a signed int.
* Useful for detecting overflow when MPI_Aint is larger than an int.
http://git.mpich.org/mpich.git/commitdiff/0d3c7a5cb0d28571008e0a415d392a88e7ce3388
commit 0d3c7a5cb0d28571008e0a415d392a88e7ce3388
Author: Dave Goodell <goodell at mcs.anl.gov>
Date: Mon Mar 18 15:49:13 2013 -0500
add static type checking asserts
If C11 `_Generic` or some equivalent functionality is present in the
compiler, statically check the type of the expression given to the
`MPIU_Assert_has_type` macro.
Reviewed-by: dinan
diff --git a/src/include/mpiutil.h b/src/include/mpiutil.h
index 552a7e7..ffb5c19 100644
--- a/src/include/mpiutil.h
+++ b/src/include/mpiutil.h
@@ -231,6 +231,20 @@ int MPIR_Assert_fail_fmt(const char *cond, const char *file_name, int line_num,
#endif
/* -------------------------------------------------------------------------- */
+/* static type checking macros */
+
+/* implement using C11's "_Generic" functionality (optimal case) */
+#ifdef HAVE_C11__GENERIC
+# define MPIU_Assert_has_type(expr_,type_) \
+ MPIU_Static_assert(_Generic((expr_), type_: 1, default: 0), \
+ "expression '" #expr_ "' does not have type '" #type_ "'")
+#endif
+/* fallthrough to do nothing */
+#ifndef MPIU_Assert_has_type
+# define MPIU_Assert_has_type(expr_,type_) do {} while (0)
+#endif
+
+/* -------------------------------------------------------------------------- */
/*
* Basic utility macros
*/
http://git.mpich.org/mpich.git/commitdiff/da86da32172780e676261e1938b4e016772a6be3
commit da86da32172780e676261e1938b4e016772a6be3
Author: Dave Goodell <goodell at mcs.anl.gov>
Date: Mon Mar 18 15:42:50 2013 -0500
detect C11 `_Generic` in some cases
Really just clang right now.
Reviewed-by: dinan
diff --git a/src/include/mpiutil.h b/src/include/mpiutil.h
index 760b0b9..552a7e7 100644
--- a/src/include/mpiutil.h
+++ b/src/include/mpiutil.h
@@ -17,6 +17,9 @@ int MPID_Abort( struct MPID_Comm *comm, int mpi_errno, int exit_code, const char
/* modern versions of clang support lots of C11 features */
#if defined(__has_extension)
+# if __has_extension(c_generic_selections)
+# define HAVE_C11__GENERIC 1
+# endif
# if __has_extension(c_static_assert)
# define HAVE_C11__STATIC_ASSERT 1
# endif
http://git.mpich.org/mpich.git/commitdiff/4cbc2d55371a92adf71e3e9253662f287e28f438
commit 4cbc2d55371a92adf71e3e9253662f287e28f438
Author: Dave Goodell <goodell at mcs.anl.gov>
Date: Mon Mar 18 14:09:28 2013 -0500
add `MPIU_Static_assert`
Adds some very useful compile-time assertions. They fall back to
runtime assertions if the compiler does not support compile-time
assertions.
Reviewed-by: dinan
diff --git a/src/include/mpiutil.h b/src/include/mpiutil.h
index 3ca2706..760b0b9 100644
--- a/src/include/mpiutil.h
+++ b/src/include/mpiutil.h
@@ -12,6 +12,24 @@ struct MPID_Comm;
int MPID_Abort( struct MPID_Comm *comm, int mpi_errno, int exit_code, const char *error_msg );
#endif
+/* -------------------------------------------------------------------------- */
+/* detect compiler characteristics from predefined preprocesor tokens */
+
+/* modern versions of clang support lots of C11 features */
+#if defined(__has_extension)
+# if __has_extension(c_static_assert)
+# define HAVE_C11__STATIC_ASSERT 1
+# endif
+#endif
+
+/* GCC 4.6 added support for _Static_assert:
+ * http://gcc.gnu.org/gcc-4.6/changes.html */
+#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined __cplusplus
+# define HAVE_C11__STATIC_ASSERT 1
+#endif
+
+/* -------------------------------------------------------------------------- */
+
/*
* MPIU_Sterror()
*
@@ -187,6 +205,29 @@ int MPIR_Assert_fail_fmt(const char *cond, const char *file_name, int line_num,
#define MPID_Ensure_Aint_fits_in_pointer(aint) \
MPIU_Assert((aint) == (MPI_Aint)(MPIR_Upint) MPI_AINT_CAST_TO_VOID_PTR(aint));
+/* -------------------------------------------------------------------------- */
+/* static assertions
+ *
+ * C11 adds static assertions. They can be faked in pre-C11 compilers through
+ * various tricks as long as you are willing to accept some ugly error messages
+ * when the assert trips. See
+ * http://www.pixelbeat.org/programming/gcc/static_assert.html
+ * for some implementation options.
+ *
+ * For now, we just use some simple preprocessor tests to use real static
+ * assertions when the compiler supports them (modern clang and gcc do).
+ * Eventually add configure logic to detect this.
+ */
+/* the case we usually want to hit */
+#ifdef HAVE_C11__STATIC_ASSERT
+# define MPIU_Static_assert(cond_,msg_) _Static_assert(cond_,msg_)
+#endif
+/* fallthrough to a run-time assertion */
+#ifndef MPIU_Static_assert
+# define MPIU_Static_assert(cond_,msg_) MPIU_Assert_fmt_msg((cond_), ("%s", (msg_)))
+#endif
+
+/* -------------------------------------------------------------------------- */
/*
* Basic utility macros
*/
http://git.mpich.org/mpich.git/commitdiff/305d986aadad4e71f59499da35f3cec4fd217595
commit 305d986aadad4e71f59499da35f3cec4fd217595
Author: Dave Goodell <goodell at mcs.anl.gov>
Date: Mon Mar 18 15:47:41 2013 -0500
add `MPIU_Prod_overflows_max`
Rename `MPIU_Assert_prod_overflow` to the more descriptive
`MPIU_Assert_prod_pos_overflow_safe` and refactor it to use the new
macro.
Reviewed-by: dinan
diff --git a/src/include/mpiutil.h b/src/include/mpiutil.h
index 828824d..3ca2706 100644
--- a/src/include/mpiutil.h
+++ b/src/include/mpiutil.h
@@ -145,16 +145,19 @@ int MPIR_Assert_fail_fmt(const char *cond, const char *file_name, int line_num,
# define MPIU_Assert_fmt_msg(cond_,fmt_arg_parens_)
#endif
+
+/* evaluates to TRUE if ((a_)*(b_)>(max_)), only detects overflow for positive
+ * a_ and _b. */
+#define MPIU_Prod_overflows_max(a_, b_, max_) \
+ ( (a_) > 0 && (b_) > 0 && ((a_) > ((max_) / (b_))) )
+
/* asserts that ((a_)*(b_)<=(max_)) holds in a way that is robust against
- * undefined overflow behavior and is suitable for both signed and unsigned math
- * (only suitable for positive values) */
-#define MPIU_Assert_prod_overflow(a_, b_, max_) \
- do { \
- if ((a_) >= 0 && (b_) >= 0) { \
- MPIU_Assert_fmt_msg((a_) <= ((max_) / (b_)), \
- ("overflow detected: %llx * %llx > %s", (a_), (b_), #max_)); \
- } \
- } while (0)
+ * undefined integer overflow behavior and is suitable for both signed and
+ * unsigned math (only suitable for positive values of (a_) and (b_)) */
+#define MPIU_Assert_prod_pos_overflow_safe(a_, b_, max_) \
+ MPIU_Assert_fmt_msg(!MPIU_Prod_overflows_max((a_),(b_),(max_)), \
+ ("overflow detected: (%llx * %llx) > %s", (a_), (b_), #max_)); \
+
/*
* Ensure an MPI_Aint value fits into a signed int.
-----------------------------------------------------------------------
Summary of changes:
src/include/mpiutil.h | 130 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 122 insertions(+), 8 deletions(-)
hooks/post-receive
--
MPICH primary repository
More information about the commits
mailing list