diff mbox

Fix tree_function_versioning with void type DECL_RESULT (PR tree-optimization/51865)

Message ID 20120115213643.GX18768@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Jan. 15, 2012, 9:36 p.m. UTC
Hi!

The recent changes in tree_function_versioning broke the following
testcase.  If DECL_RESULT exists, but has void type, then we used to
remap_decl it before, but now we don't, so in this case the same RESULT_DECL
is used in two different functions, which upsets ipa-pta, but could upset
other code too.

Fixed by calling remap_decl again for void type.  Bootstrapped/regtested
on x86_64-linux and i686-linux (on x86_64 including ada).  Ok for trunk?

2012-01-15  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/51865
	* tree-inline.c (tree_function_versioning): Call remap_decl
	on DECL_RESULT whenever it has VOID_TYPE_P type.

	* gcc.dg/pr51865.c: New test.


	Jakub

Comments

Richard Biener Jan. 16, 2012, 8:31 a.m. UTC | #1
On Sun, 15 Jan 2012, Jakub Jelinek wrote:

> Hi!
> 
> The recent changes in tree_function_versioning broke the following
> testcase.  If DECL_RESULT exists, but has void type, then we used to
> remap_decl it before, but now we don't, so in this case the same RESULT_DECL
> is used in two different functions, which upsets ipa-pta, but could upset
> other code too.
> 
> Fixed by calling remap_decl again for void type.  Bootstrapped/regtested
> on x86_64-linux and i686-linux (on x86_64 including ada).  Ok for trunk?

Ok.

Thanks,
Richard.

> 2012-01-15  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/51865
> 	* tree-inline.c (tree_function_versioning): Call remap_decl
> 	on DECL_RESULT whenever it has VOID_TYPE_P type.
> 
> 	* gcc.dg/pr51865.c: New test.
> 
> --- gcc/tree-inline.c.jj	2012-01-13 21:47:35.000000000 +0100
> +++ gcc/tree-inline.c	2012-01-15 20:00:00.350918475 +0100
> @@ -5201,9 +5201,9 @@ tree_function_versioning (tree old_decl,
>      /* Add local vars.  */
>      add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id, false);
>  
> -  if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
> +  if (DECL_RESULT (old_decl) == NULL_TREE)
>      ;
> -  else if (skip_return)
> +  else if (skip_return && !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
>      {
>        DECL_RESULT (new_decl)
>  	= build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)),
> --- gcc/testsuite/gcc.dg/pr51865.c.jj	2012-01-15 20:09:00.035734459 +0100
> +++ gcc/testsuite/gcc.dg/pr51865.c	2012-01-15 20:08:42.000000000 +0100
> @@ -0,0 +1,25 @@
> +/* PR tree-optimization/51865 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fipa-pta" } */
> +
> +void fn (const char *, const char *) __attribute__ ((__noreturn__));
> +int var;
> +
> +inline void
> +foo (void)
> +{
> +  if (__builtin_expect (var != 0, 0))
> +    fn ("a", "b");
> +};
> +
> +void
> +bar (void)
> +{
> +  foo ();
> +};
> +
> +void
> +baz (void)
> +{
> +  foo ();
> +};
> 
> 	Jakub
> 
>
Eric Botcazou Jan. 17, 2012, 12:03 p.m. UTC | #2
> The recent changes in tree_function_versioning broke the following
> testcase.  If DECL_RESULT exists, but has void type, then we used to
> remap_decl it before, but now we don't, so in this case the same
> RESULT_DECL is used in two different functions, which upsets ipa-pta, but
> could upset other code too.
>
> Fixed by calling remap_decl again for void type.  Bootstrapped/regtested
> on x86_64-linux and i686-linux (on x86_64 including ada).  Ok for trunk?
>
> 2012-01-15  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR tree-optimization/51865
> 	* tree-inline.c (tree_function_versioning): Call remap_decl
> 	on DECL_RESULT whenever it has VOID_TYPE_P type.
>
> 	* gcc.dg/pr51865.c: New test.

Thanks for fixing this!
diff mbox

Patch

--- gcc/tree-inline.c.jj	2012-01-13 21:47:35.000000000 +0100
+++ gcc/tree-inline.c	2012-01-15 20:00:00.350918475 +0100
@@ -5201,9 +5201,9 @@  tree_function_versioning (tree old_decl,
     /* Add local vars.  */
     add_local_variables (DECL_STRUCT_FUNCTION (old_decl), cfun, &id, false);
 
-  if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
+  if (DECL_RESULT (old_decl) == NULL_TREE)
     ;
-  else if (skip_return)
+  else if (skip_return && !VOID_TYPE_P (TREE_TYPE (DECL_RESULT (old_decl))))
     {
       DECL_RESULT (new_decl)
 	= build_decl (DECL_SOURCE_LOCATION (DECL_RESULT (old_decl)),
--- gcc/testsuite/gcc.dg/pr51865.c.jj	2012-01-15 20:09:00.035734459 +0100
+++ gcc/testsuite/gcc.dg/pr51865.c	2012-01-15 20:08:42.000000000 +0100
@@ -0,0 +1,25 @@ 
+/* PR tree-optimization/51865 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fipa-pta" } */
+
+void fn (const char *, const char *) __attribute__ ((__noreturn__));
+int var;
+
+inline void
+foo (void)
+{
+  if (__builtin_expect (var != 0, 0))
+    fn ("a", "b");
+};
+
+void
+bar (void)
+{
+  foo ();
+};
+
+void
+baz (void)
+{
+  foo ();
+};