This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, PR 40582] Stricter type requirements in build_ref_for_offset


On Tue, 30 Jun 2009, Martin Jambor wrote:

> Hi,
> 
> the patch  below fixes  PR 40582.  It turns out  the problem  was that
> build_ref_for_offset was  too lenient when deciding  what types match.
> When the function  is called, it is either allowed to  fail or we know
> that the types are such that  there is a match.  However, in unions it
> might have  accidentally matched a  wrong one, creating  an assignment
> which is not valid.
> 
> Bootstrapped and tested on x86_64-linux, OK for trunk?

Ok.

Thanks,
Richard.

> Thanks,
> 
> Martin
> 
> 
> 2009-06-30  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR tree-optimization/40582
> 	* tree-sra.c (build_ref_for_offset_1): Use types_compatible_p rather
> 	than useless_type_conversion_p.
> 	(generate_subtree_copies): Increment sra_stats.subtree_copies at a
> 	proper place.
> 
> 	* testsuite/gcc.c-torture/compile/pr40582.c: New test.
> 
> Index: mine/gcc/tree-sra.c
> ===================================================================
> --- mine.orig/gcc/tree-sra.c
> +++ mine/gcc/tree-sra.c
> @@ -1036,7 +1036,7 @@ build_ref_for_offset_1 (tree *res, tree
>        HOST_WIDE_INT el_size;
>  
>        if (offset == 0 && exp_type
> -	  && useless_type_conversion_p (exp_type, type))
> +	  && types_compatible_p (exp_type, type))
>  	return true;
>  
>        switch (TREE_CODE (type))
> @@ -1760,7 +1760,6 @@ generate_subtree_copies (struct access *
>  						 insert_after ? GSI_NEW_STMT
>  						 : GSI_SAME_STMT);
>  	      stmt = gimple_build_assign (expr, repl);
> -	      sra_stats.subtree_copies++;
>  	    }
>  
>  	  if (insert_after)
> @@ -1768,6 +1767,7 @@ generate_subtree_copies (struct access *
>  	  else
>  	    gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
>  	  update_stmt (stmt);
> +	  sra_stats.subtree_copies++;
>  	}
>  
>        if (access->first_child)
> Index: mine/gcc/testsuite/gcc.c-torture/compile/pr40582.c
> ===================================================================
> --- /dev/null
> +++ mine/gcc/testsuite/gcc.c-torture/compile/pr40582.c
> @@ -0,0 +1,18 @@
> +struct A
> +{
> +  void* q;
> +  short i;
> +};
> +
> +union U
> +{
> +  char* p;
> +  struct A a;
> +};
> +
> +struct A foo(union U u)
> +{
> +  struct A a = { 0, 0 };
> +  a = u.a;
> +  return a;
> +}
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]