[PATCH] Fix PR39041, wrong types from forwprop

Richard Guenther rguenther@suse.de
Fri Jan 30 22:09:00 GMT 2009


forwprop ignores type compatibility on propagating non-constant
array indices.  This causes later an ICE after VRP which manages
to create even more invalid IL out of the garbage.

Bootstrapped and tested on x86_64-unknown-linux-gnu, trunk and branch,
committed to both.

Richard.

2009-01-30  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/39041
	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1):
	Propagate variable indices only if the types match for this stmt.

	* gcc.c-torture/compile/pr39041.c: New testcase.

Index: gcc/tree-ssa-forwprop.c
===================================================================
*** gcc/tree-ssa-forwprop.c	(revision 143788)
--- gcc/tree-ssa-forwprop.c	(working copy)
*************** forward_propagate_addr_expr_1 (tree name
*** 677,682 ****
--- 677,683 ----
       array elements, then the result is converted into the proper
       type for the arithmetic.  */
    if (TREE_CODE (TREE_OPERAND (rhs, 1)) == SSA_NAME
+       && useless_type_conversion_p (TREE_TYPE (name), TREE_TYPE (def_rhs))
        /* Avoid problems with IVopts creating PLUS_EXPRs with a
  	 different type than their operands.  */
        && useless_type_conversion_p (TREE_TYPE (rhs), TREE_TYPE (name)))
Index: gcc/testsuite/gcc.c-torture/compile/pr39041.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr39041.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr39041.c	(revision 0)
***************
*** 0 ****
--- 1,28 ----
+ int test_bit(int nr, void *addr)
+ {
+   int *a = (int *)addr;
+   int mask;
+   a += nr;
+   mask = 1 << nr;
+   return mask & *a;
+ }
+ struct {
+     struct {
+ 	int disabled;
+     } *data[1];
+ } trace;
+ struct {
+     unsigned bits[1];
+ } cpumask;
+ void inc(int *);
+ void dec(int *);
+ int foo(void)
+ {
+   int cpu;
+   for (cpu = 0; cpu < 1; cpu++) {
+       if (test_bit(cpu, cpumask.bits))
+ 	inc(&trace.data[cpu]->disabled);
+       if (!test_bit(cpu, cpumask.bits))
+ 	dec(&trace.data[cpu]->disabled);
+   }
+ }



More information about the Gcc-patches mailing list