diff options
author | Richard Biener <rguenther@suse.de> | 2022-07-25 17:24:57 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-07-26 08:36:53 +0200 |
commit | bb04f9f23ac0dee2c003118c85372ece50a52220 (patch) | |
tree | ad94a3fb78bd8d22720410f2468d0344dbe77894 /gcc/gimple-array-bounds.cc | |
parent | 16fc26d4e7a4a7618d8d231f9b4cb7bd487fb7b8 (diff) | |
download | gcc-bb04f9f23ac0dee2c003118c85372ece50a52220.zip gcc-bb04f9f23ac0dee2c003118c85372ece50a52220.tar.gz gcc-bb04f9f23ac0dee2c003118c85372ece50a52220.tar.bz2 |
tree-optimization/106189 - avoid division by zero exception
The diagnostic code can end up with zero sized array elements
with T[][0] and the wide-int code nicely avoids exceptions when
dividing by zero in one codepath but not in another. The following
fixes the exception by using wide-int in both paths.
PR tree-optimization/106189
* gimple-array-bounds.cc (array_bounds_checker::check_mem_ref):
Divide using offset_ints.
* gcc.dg/pr106189.c: New testcase.
Diffstat (limited to 'gcc/gimple-array-bounds.cc')
-rw-r--r-- | gcc/gimple-array-bounds.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 0b48bdb..e190b93 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -534,7 +534,7 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, int i = 0; if (aref.offmax[i] < -aref.sizrng[1] || aref.offmax[i = 1] > ubound) { - HOST_WIDE_INT tmpidx = aref.offmax[i].to_shwi () / eltsize.to_shwi (); + HOST_WIDE_INT tmpidx = (aref.offmax[i] / eltsize).to_shwi (); if (warning_at (location, OPT_Warray_bounds, "intermediate array offset %wi is outside array bounds " |