diff --git a/cunumeric/deferred.py b/cunumeric/deferred.py index c887ac09b..7d575105f 100644 --- a/cunumeric/deferred.py +++ b/cunumeric/deferred.py @@ -391,6 +391,7 @@ def _zip_indices(self, start_index, arrays): # call ZIP function to combine index arrays into a singe array task = self.context.create_task(CuNumericOpCode.ZIP) + task.throws_exception(IndexError) task.add_output(output_arr.base) task.add_scalar_arg(self.ndim, ty.int64) # N of points in Point task.add_scalar_arg(key_dim, ty.int64) # key_dim diff --git a/src/cunumeric/index/zip.h b/src/cunumeric/index/zip.h index 4cd5f1b4d..61a87104c 100644 --- a/src/cunumeric/index/zip.h +++ b/src/cunumeric/index/zip.h @@ -43,9 +43,12 @@ class ZipTask : public CuNumericTask { #endif }; -constexpr coord_t compute_idx(coord_t index, coord_t dim) +constexpr coord_t compute_idx(coord_t index, coord_t extent) { - return index < 0 ? index + dim : index; + coord_t new_index = index < 0 ? index + extent : index; + if (new_index < 0 || new_index >= extent) + throw legate::TaskException("index is out of bounds in index array"); + return new_index; } } // namespace cunumeric