]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/107554 - fix ICE in stlen optimization
authorRichard Biener <rguenther@suse.de>
Fri, 11 Nov 2022 13:28:52 +0000 (14:28 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 11 Nov 2022 14:04:53 +0000 (15:04 +0100)
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>
gcc/testsuite/gcc.dg/pr107554.c [new file with mode: 0644]
gcc/tree-ssa-strlen.cc

diff --git a/gcc/testsuite/gcc.dg/pr107554.c b/gcc/testsuite/gcc.dg/pr107554.c
new file mode 100644 (file)
index 0000000..8bbe6b0
--- /dev/null
@@ -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));
+}
index b87c7c7ce1f73ad84cb5b2bf9745eafbca81f60f..abec225566d0bddca5757e90a95861a17b279bd1 100644 (file)
@@ -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;