Fix ICE in compute_objsize (PR tree-optimization/92891)
diff mbox series

Message ID 20191210232350.GN10088@tucnak
State New
Headers show
Series
  • Fix ICE in compute_objsize (PR tree-optimization/92891)
Related show

Commit Message

Jakub Jelinek Dec. 10, 2019, 11:23 p.m. UTC
Hi!

The following testcase ICEs, because gimple_call_alloc_size doesn't always
return a sizetype typed INTEGER_CST, which the callers rely on (compare
those converted to wide_int with other wide_ints with the sizetype
precision).  If alloc_size attribute has two arguments,
gimple_call_alloc_size will always build a sizetype INTEGER_CST,
but if it is just one, it returns what is passed to the argument,
whatever type it has, so could be wider (e.g. __int128) or narrower
like in the testcase on lp64.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2019-12-10  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/92891
	* builtins.c (gimple_call_alloc_size): Convert size to sizetype
	before returning it.

	* gcc.c-torture/compile/pr92891.c: New test.


	Jakub

Comments

Jeff Law Dec. 10, 2019, 11:31 p.m. UTC | #1
On Wed, 2019-12-11 at 00:23 +0100, Jakub Jelinek wrote:
> Hi!
> 
> The following testcase ICEs, because gimple_call_alloc_size doesn't
> always
> return a sizetype typed INTEGER_CST, which the callers rely on
> (compare
> those converted to wide_int with other wide_ints with the sizetype
> precision).  If alloc_size attribute has two arguments,
> gimple_call_alloc_size will always build a sizetype INTEGER_CST,
> but if it is just one, it returns what is passed to the argument,
> whatever type it has, so could be wider (e.g. __int128) or narrower
> like in the testcase on lp64.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for
> trunk?
> 
> 2019-12-10  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/92891
> 	* builtins.c (gimple_call_alloc_size): Convert size to sizetype
> 	before returning it.
> 
> 	* gcc.c-torture/compile/pr92891.c: New test.
OK.

jeff
>

Patch
diff mbox series

--- gcc/builtins.c.jj	2019-12-09 19:50:24.733953169 +0100
+++ gcc/builtins.c	2019-12-10 20:56:53.619769947 +0100
@@ -3755,7 +3755,7 @@  gimple_call_alloc_size (gimple *stmt)
     return NULL_TREE;
 
   if (argidx2 > nargs && TREE_CODE (size) == INTEGER_CST)
-    return size;
+    return fold_convert (sizetype, size);
 
   /* To handle ranges do the math in wide_int and return the product
      of the upper bounds as a constant.  Ignore anti-ranges.  */
--- gcc/testsuite/gcc.c-torture/compile/pr92891.c.jj	2019-12-10 21:09:14.137648344 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr92891.c	2019-12-10 21:08:56.902907013 +0100
@@ -0,0 +1,16 @@ 
+/* PR tree-optimization/92891 */
+
+int a, b;
+char *foo (int) __attribute__((alloc_size(1)));
+
+void
+bar (void)
+{
+  char *e = foo (2);
+  while (a)
+    {
+      if (b <= 0)
+	continue;
+      e[b] = 0;
+    }
+}