Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383)

Message ID 20180215000430.GE5867@tucnak
State New
Headers show
Series
  • Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383)
Related show

Commit Message

Jakub Jelinek Feb. 15, 2018, 12:04 a.m.
Hi!

The function calls get_addr_base_and_unit_offset on 2 trees, but
that can return NULL if the unit offset is not constant.
The conditional tests just one of them for non-NULL and operand_equal_p
ICEs if one argument is NULL, so depending on the uninitialized poly_int64
(get_addr_base_and_unit_offset doesn't touch it if it returns NULL),
we either ICE in operand_equal_p or are lucky and dstoff is equal to lhsoff
and just valgrind complains.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2018-02-15  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/84383
	* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Don't look at
	dstoff nor call operand_equal_p if dstbase is NULL.

	* gcc.c-torture/compile/pr84383.c: New test.


	Jakub

Comments

Richard Biener Feb. 15, 2018, 9:59 a.m. | #1
On Thu, 15 Feb 2018, Jakub Jelinek wrote:

> Hi!

> 

> The function calls get_addr_base_and_unit_offset on 2 trees, but

> that can return NULL if the unit offset is not constant.

> The conditional tests just one of them for non-NULL and operand_equal_p

> ICEs if one argument is NULL, so depending on the uninitialized poly_int64

> (get_addr_base_and_unit_offset doesn't touch it if it returns NULL),

> we either ICE in operand_equal_p or are lucky and dstoff is equal to lhsoff

> and just valgrind complains.

> 

> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for

> trunk?


Ok.

Richard.

> 2018-02-15  Jakub Jelinek  <jakub@redhat.com>

> 

> 	PR tree-optimization/84383

> 	* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Don't look at

> 	dstoff nor call operand_equal_p if dstbase is NULL.

> 

> 	* gcc.c-torture/compile/pr84383.c: New test.

> 

> --- gcc/tree-ssa-strlen.c.jj	2018-02-09 06:44:29.993809176 +0100

> +++ gcc/tree-ssa-strlen.c	2018-02-14 16:38:36.981713666 +0100

> @@ -1878,6 +1878,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_it

>        poly_int64 lhsoff;

>        tree lhsbase = get_addr_base_and_unit_offset (lhs, &lhsoff);

>        if (lhsbase

> +	  && dstbase

>  	  && known_eq (dstoff, lhsoff)

>  	  && operand_equal_p (dstbase, lhsbase, 0))

>  	return false;

> --- gcc/testsuite/gcc.c-torture/compile/pr84383.c.jj	2018-02-14 17:33:21.972803287 +0100

> +++ gcc/testsuite/gcc.c-torture/compile/pr84383.c	2018-02-14 17:32:37.639803918 +0100

> @@ -0,0 +1,14 @@

> +/* PR tree-optimization/84383 */

> +

> +struct S { char *s; };

> +void bar (struct S *);

> +

> +void

> +foo (int a, char *b)

> +{

> +  struct S c[4];

> +  bar (c);

> +  __builtin_strncpy (c[a].s, b, 32);

> +  c[a].s[31] = '\0';

> +  bar (c);

> +}

> 

> 	Jakub

> 

> 


-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

Patch

--- gcc/tree-ssa-strlen.c.jj	2018-02-09 06:44:29.993809176 +0100
+++ gcc/tree-ssa-strlen.c	2018-02-14 16:38:36.981713666 +0100
@@ -1878,6 +1878,7 @@  maybe_diag_stxncpy_trunc (gimple_stmt_it
       poly_int64 lhsoff;
       tree lhsbase = get_addr_base_and_unit_offset (lhs, &lhsoff);
       if (lhsbase
+	  && dstbase
 	  && known_eq (dstoff, lhsoff)
 	  && operand_equal_p (dstbase, lhsbase, 0))
 	return false;
--- gcc/testsuite/gcc.c-torture/compile/pr84383.c.jj	2018-02-14 17:33:21.972803287 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr84383.c	2018-02-14 17:32:37.639803918 +0100
@@ -0,0 +1,14 @@ 
+/* PR tree-optimization/84383 */
+
+struct S { char *s; };
+void bar (struct S *);
+
+void
+foo (int a, char *b)
+{
+  struct S c[4];
+  bar (c);
+  __builtin_strncpy (c[a].s, b, 32);
+  c[a].s[31] = '\0';
+  bar (c);
+}