public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383)
@ 2018-02-15  0:49 Jakub Jelinek
  2018-02-15  9:59 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-02-15  0:49 UTC (permalink / raw)
  To: Richard Biener, Jeff Law, Martin Sebor; +Cc: gcc-patches

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.

--- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383)
  2018-02-15  0:49 [PATCH] Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383) Jakub Jelinek
@ 2018-02-15  9:59 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2018-02-15  9:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, Martin Sebor, gcc-patches

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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-15  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15  0:49 [PATCH] Fix ICE in maybe_diag_stxncpy_trunc (PR tree-optimization/84383) Jakub Jelinek
2018-02-15  9:59 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).