objsz: Don't call replace_uses_by on SSA_NAME_OCCURS_IN_ABNORMAL_PHI [PR94423]

Message ID 20200401071548.GH2212@tucnak
State New
Headers show
Series
  • objsz: Don't call replace_uses_by on SSA_NAME_OCCURS_IN_ABNORMAL_PHI [PR94423]
Related show

Commit Message

Iain Buclaw via Gcc-patches April 1, 2020, 7:15 a.m.
Hi!

The following testcase ICEs because the objsz pass calls replace_uses_by
on SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAME.  The following patch instead
of that calls replace_call_with_value, which will turn it into
  xyz_123(ab) = 234;

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-04-01  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/94423
	* tree-object-size.c (pass_object_sizes::execute): Don't call
	replace_uses_by for SSA_NAME_OCCURS_IN_ABNORMAL_PHI lhs, instead
	call replace_call_with_value.

	* gcc.dg/ubsan/pr94423.c: New test.


	Jakub

Comments

Richard Biener April 1, 2020, 7:28 a.m. | #1
On Wed, 1 Apr 2020, Jakub Jelinek wrote:

> Hi!

> 

> The following testcase ICEs because the objsz pass calls replace_uses_by

> on SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAME.  The following patch instead

> of that calls replace_call_with_value, which will turn it into

>   xyz_123(ab) = 234;

> 

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


OK.

Thanks,
Richard.

> 2020-04-01  Jakub Jelinek  <jakub@redhat.com>

> 

> 	PR middle-end/94423

> 	* tree-object-size.c (pass_object_sizes::execute): Don't call

> 	replace_uses_by for SSA_NAME_OCCURS_IN_ABNORMAL_PHI lhs, instead

> 	call replace_call_with_value.

> 

> 	* gcc.dg/ubsan/pr94423.c: New test.

> 

> --- gcc/tree-object-size.c.jj	2020-01-12 11:54:38.498381952 +0100

> +++ gcc/tree-object-size.c	2020-03-31 14:35:34.956831791 +0200

> @@ -1393,7 +1393,10 @@ pass_object_sizes::execute (function *fu

>  	    }

>  

>  	  /* Propagate into all uses and fold those stmts.  */

> -	  replace_uses_by (lhs, result);

> +	  if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))

> +	    replace_uses_by (lhs, result);

> +	  else

> +	    replace_call_with_value (&i, result);

>  	}

>      }

>  

> --- gcc/testsuite/gcc.dg/ubsan/pr94423.c.jj	2020-03-31 14:38:15.101423280 +0200

> +++ gcc/testsuite/gcc.dg/ubsan/pr94423.c	2020-03-31 14:32:31.562589949 +0200

> @@ -0,0 +1,17 @@

> +/* PR middle-end/94423 */

> +/* { dg-do compile } */

> +/* { dg-options "-O2 -fsanitize=object-size" } */

> +

> +void foo (void);

> +typedef struct { long buf[22]; } jmp_buf[1];

> +extern int sigsetjmp (jmp_buf, int) __attribute__ ((__nothrow__));

> +jmp_buf buf;

> +

> +void

> +bar (int *c)

> +{

> +  while (*c)

> +    foo ();

> +  while (*c)

> +    sigsetjmp (buf, 0);

> +}

> 

> 	Jakub

> 

> 


-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Patch

--- gcc/tree-object-size.c.jj	2020-01-12 11:54:38.498381952 +0100
+++ gcc/tree-object-size.c	2020-03-31 14:35:34.956831791 +0200
@@ -1393,7 +1393,10 @@  pass_object_sizes::execute (function *fu
 	    }
 
 	  /* Propagate into all uses and fold those stmts.  */
-	  replace_uses_by (lhs, result);
+	  if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
+	    replace_uses_by (lhs, result);
+	  else
+	    replace_call_with_value (&i, result);
 	}
     }
 
--- gcc/testsuite/gcc.dg/ubsan/pr94423.c.jj	2020-03-31 14:38:15.101423280 +0200
+++ gcc/testsuite/gcc.dg/ubsan/pr94423.c	2020-03-31 14:32:31.562589949 +0200
@@ -0,0 +1,17 @@ 
+/* PR middle-end/94423 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsanitize=object-size" } */
+
+void foo (void);
+typedef struct { long buf[22]; } jmp_buf[1];
+extern int sigsetjmp (jmp_buf, int) __attribute__ ((__nothrow__));
+jmp_buf buf;
+
+void
+bar (int *c)
+{
+  while (*c)
+    foo ();
+  while (*c)
+    sigsetjmp (buf, 0);
+}