Patchwork Fix type consistency problem in tree-tailcall.c

login
register
mail settings
Submitter Eric Botcazou
Date Nov. 3, 2010, 10:26 a.m.
Message ID <201011031126.47769.ebotcazou@adacore.com>
Download mbox | patch
Permalink /patch/69964/
State New
Headers show

Comments

Eric Botcazou - Nov. 3, 2010, 10:26 a.m.
Hi,

the attached testcase exhibits a regression present at -O2 on the mainline 
with checking enabled:

/home/eric/svn/gcc/gcc/testsuite/gnat.dg/opt8.adb:25:5: error: type mismatch 
in binary expression
natural___XDLU_0__2147483647
const integer
natural___XDLU_0__2147483647
D.2693_51 = R3b_27 + add_acc.25_49;
+===========================GNAT BUG DETECTED==============================+
| 4.6.0 20101102 (experimental) [trunk revision 166172] (i586-suse-linux-gnu) 
GCC error:|
| verify_stmts failed                                                      |
| Error detected 
around /home/eric/svn/gcc/gcc/testsuite/gnat.dg/opt8.adb:25:5|


The problem is that, while the code to discover tail calls knows how to look 
through casts, it doesn't reinstate them when it is building expressions to 
compute the accumulator and multiplicator values.  Hence the attached patch.

Tested on i586-suse-linux, OK for the mainline?


2010-11-03  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-tailcall.c (find_tail_calls): Convert the operands to the type
	of the result before building binary expressions.


2010-11-03  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt8.ad[sb]: New test.
	* gnat.dg/opt8_pkg.ads: New helper.
Richard Guenther - Nov. 3, 2010, 10:49 a.m.
On Wed, Nov 3, 2010 at 11:26 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> the attached testcase exhibits a regression present at -O2 on the mainline
> with checking enabled:
>
> /home/eric/svn/gcc/gcc/testsuite/gnat.dg/opt8.adb:25:5: error: type mismatch
> in binary expression
> natural___XDLU_0__2147483647
> const integer
> natural___XDLU_0__2147483647
> D.2693_51 = R3b_27 + add_acc.25_49;
> +===========================GNAT BUG DETECTED==============================+
> | 4.6.0 20101102 (experimental) [trunk revision 166172] (i586-suse-linux-gnu)
> GCC error:|
> | verify_stmts failed                                                      |
> | Error detected
> around /home/eric/svn/gcc/gcc/testsuite/gnat.dg/opt8.adb:25:5|
>
>
> The problem is that, while the code to discover tail calls knows how to look
> through casts, it doesn't reinstate them when it is building expressions to
> compute the accumulator and multiplicator values.  Hence the attached patch.
>
> Tested on i586-suse-linux, OK for the mainline?

Ok.

Thanks,
Richard.

>
> 2010-11-03  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * tree-tailcall.c (find_tail_calls): Convert the operands to the type
>        of the result before building binary expressions.
>
>
> 2010-11-03  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * gnat.dg/opt8.ad[sb]: New test.
>        * gnat.dg/opt8_pkg.ads: New helper.
>
>
> --
> Eric Botcazou
>

Patch

Index: tree-tailcall.c
===================================================================
--- tree-tailcall.c	(revision 166172)
+++ tree-tailcall.c	(working copy)
@@ -532,20 +532,22 @@  find_tail_calls (basic_block bb, struct
 
       if (tmp_a)
 	{
+	  tree type = TREE_TYPE (tmp_a);
 	  if (a)
-	    a = fold_build2 (PLUS_EXPR, TREE_TYPE (tmp_a), a, tmp_a);
+	    a = fold_build2 (PLUS_EXPR, type, fold_convert (type, a), tmp_a);
 	  else
 	    a = tmp_a;
 	}
       if (tmp_m)
 	{
+	  tree type = TREE_TYPE (tmp_m);
 	  if (m)
-	    m = fold_build2 (MULT_EXPR, TREE_TYPE (tmp_m), m, tmp_m);
+	    m = fold_build2 (MULT_EXPR, type, fold_convert (type, m), tmp_m);
 	  else
 	    m = tmp_m;
 
 	  if (a)
-	    a = fold_build2 (MULT_EXPR, TREE_TYPE (tmp_m), a, tmp_m);
+	    a = fold_build2 (MULT_EXPR, type, fold_convert (type, a), tmp_m);
 	}
     }