From: Richard Biener Date: Fri, 11 Nov 2022 13:28:52 +0000 (+0100) Subject: tree-optimization/107554 - fix ICE in stlen optimization X-Git-Tag: release-12.2.mpacbti-rel1~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca8b8191983d1a211a718b39ca07e35b8c626416;p=thirdparty%2Fgcc.git 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 (cherry picked from commit 81de4037454275f8ed6d858fbc129e832c6147ef) --- diff --git a/gcc/testsuite/gcc.dg/pr107554.c b/gcc/testsuite/gcc.dg/pr107554.c new file mode 100644 index 000000000000..8bbe6b07ae91 --- /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 2d7db6da5bc0..cb7ccb41d73a 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -4700,7 +4700,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;