diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-01-20 17:15:00 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-01-20 17:15:00 -0500 |
commit | 3826479b859280f52e0122908ec0429574b26789 (patch) | |
tree | 45f7b4d9881f8784852e83a160fac0332dd35060 /Carpet | |
parent | 3192a5cc2740e8d801a72d6efd1103c8cca5a1d4 (diff) |
LoopControl: Add assert statements to loop macros to catch indexing errors
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/LoopControl/src/loopcontrol.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Carpet/LoopControl/src/loopcontrol.h b/Carpet/LoopControl/src/loopcontrol.h index 00d0ce8ca..7080f274f 100644 --- a/Carpet/LoopControl/src/loopcontrol.h +++ b/Carpet/LoopControl/src/loopcontrol.h @@ -10,11 +10,16 @@ #ifdef CCODE +#include <assert.h> #include <stddef.h> #include <stdlib.h> #include <cctk.h> +#define lc_assert(x) assert(x) + + + #ifdef __cplusplus extern "C" { #endif @@ -142,6 +147,9 @@ extern "C" { lc_fmax0 = lc_control.fine.max.v[0]; \ ptrdiff_t imin = lc_fmin0; \ ptrdiff_t imax = lc_fmax0; \ + lc_assert(lc_fmin0 < lc_fmax0); \ + lc_assert(lc_fmin0 >= lc_control.loop.min.v[0]); \ + lc_assert(lc_fmax0 <= lc_control.loop.max.v[0]); \ int const lc_fmin0_is_outer = lc_fmin0 == lc_control.loop.min.v[0]; \ int const lc_fmax0_is_outer = lc_fmax0 == lc_control.loop.max.v[0]; \ ptrdiff_t const lc_iminpos = lc_fmin0 + lc_ash0 * (j + lc_ash1 * k); \ @@ -150,8 +158,12 @@ extern "C" { ptrdiff_t const lc_imaxoffset = lc_imaxpos % lc_align0; \ lc_fmin0 -= lc_iminoffset; \ if (!lc_fmax0_is_outer) lc_fmax0 -= lc_imaxoffset; \ + lc_assert(lc_fmin0 < lc_fmax0); \ if (!lc_fmin0_is_outer) imin = lc_fmin0; \ - if (!lc_fmax0_is_outer) imax = lc_fmax0; + if (!lc_fmax0_is_outer) imax = lc_fmax0; \ + lc_assert(imin >= lc_control.loop.min.v[0]); \ + lc_assert(imax <= lc_control.loop.max.v[0]); \ + lc_assert(imin < imax); #endif #define LC_SELFTEST(i,j,k, imin,imax) \ |