diff options
Diffstat (limited to 'libgfortran/generated/cshift0_c10.c')
-rw-r--r-- | libgfortran/generated/cshift0_c10.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libgfortran/generated/cshift0_c10.c b/libgfortran/generated/cshift0_c10.c index 43e173bf417..ba27a9ed4ae 100644 --- a/libgfortran/generated/cshift0_c10.c +++ b/libgfortran/generated/cshift0_c10.c @@ -97,9 +97,13 @@ cshift0_c10 (gfc_array_c10 *ret, const gfc_array_c10 *array, ptrdiff_t shift, rptr = ret->base_addr; sptr = array->base_addr; - shift = len == 0 ? 0 : shift % (ptrdiff_t)len; - if (shift < 0) - shift += len; + /* Avoid the costly modulo for trivially in-bound shifts. */ + if (shift < 0 || shift >= len) + { + shift = len == 0 ? 0 : shift % (ptrdiff_t)len; + if (shift < 0) + shift += len; + } while (rptr) { |