diff options
author | Richard Biener <rguenther@suse.de> | 2022-11-11 14:28:52 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-11-11 15:04:53 +0100 |
commit | 81de4037454275f8ed6d858fbc129e832c6147ef (patch) | |
tree | b8d2b0686636bd309172205de1d9ff31cd3a5d03 | |
parent | 4b3874d803e7961f38b22fa798517a63171bb985 (diff) | |
download | gcc-81de4037454275f8ed6d858fbc129e832c6147ef.zip gcc-81de4037454275f8ed6d858fbc129e832c6147ef.tar.gz gcc-81de4037454275f8ed6d858fbc129e832c6147ef.tar.bz2 |
tree-optimization/107554 - fix ICE in stlen optimization
The following fixes a wrongly typed variable causing an ICE.
PR tree-optimization/107554
* tree-ssa-strlen.cc (strlen_pass::count_nonzero_bytes):
Use unsigned HOST_WIDE_INT type for the strlen.
* gcc.dg/pr107554.c: New testcase.
Co-Authored-By: Nikita Voronov <nik_1357@mail.ru>
-rw-r--r-- | gcc/testsuite/gcc.dg/pr107554.c | 12 | ||||
-rw-r--r-- | gcc/tree-ssa-strlen.cc | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/pr107554.c b/gcc/testsuite/gcc.dg/pr107554.c new file mode 100644 index 0000000..8bbe6b0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107554.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O -foptimize-strlen" } */ + +#define ELEMS 0x40000000 + +int a[ELEMS]; +int b[ELEMS]; + +int main() +{ + __builtin_memcpy(a, b, ELEMS*sizeof(int)); +} diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index b87c7c7..abec225 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -4735,7 +4735,7 @@ strlen_pass::count_nonzero_bytes (tree exp, gimple *stmt, /* Compute the number of leading nonzero bytes in the representation and update the minimum and maximum. */ - unsigned n = prep ? strnlen (prep, nbytes) : nbytes; + unsigned HOST_WIDE_INT n = prep ? strnlen (prep, nbytes) : nbytes; if (n < lenrange[0]) lenrange[0] = n; |