public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix -Wrestrict SSA_NAME handling (PR c/83989)
@ 2018-01-25 22:20 Jakub Jelinek
  2018-01-26 11:22 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-01-25 22:20 UTC (permalink / raw)
  To: Richard Biener, Jeff Law, Martin Sebor; +Cc: gcc-patches

Hi!

builtin_memref ctor for a SSA_NAME with non-NULL SSA_NAME_VAR returns
the underlying variable, rather than just the SSA_NAME.
Later on the code checks if the bases are equal and then compares
corresponding offsets.

The fact that two different SSA_NAMEs have the same underlying variable
says nothing at all whether they have the same value, as the testcase shows,
either the SSA_NAMEs can be completely unrelated, or related, but with
different offsets.  The code already has code to handle POINTER_PLUS_EXPR
with a constant offset, to look through that.  Perhaps in the future there
can be other cases we'd special case, but generally we should compare as
bases the SSA_NAMEs, if they have the same or different base says nothing
about them.

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

2018-01-25  Jakub Jelinek  <jakub@redhat.com>

	PR c/83989
	* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Don't
	use SSA_NAME_VAR as base for SSA_NAMEs with non-NULL SSA_NAME_VAR.

	* c-c++-common/Wrestrict-3.c: New test.

--- gcc/gimple-ssa-warn-restrict.c.jj	2018-01-17 11:54:17.000000000 +0100
+++ gcc/gimple-ssa-warn-restrict.c	2018-01-25 14:10:26.182498552 +0100
@@ -373,9 +373,6 @@ builtin_memref::builtin_memref (tree exp
 		  offrange[1] += off;
 		}
 	    }
-
-	if (TREE_CODE (base) == SSA_NAME && SSA_NAME_VAR (base))
-	  base = SSA_NAME_VAR (base);
       }
 
   if (size)
--- gcc/testsuite/c-c++-common/Wrestrict-3.c.jj	2018-01-25 14:16:01.574563425 +0100
+++ gcc/testsuite/c-c++-common/Wrestrict-3.c	2018-01-25 14:14:39.273547506 +0100
@@ -0,0 +1,48 @@
+/* PR c/83989 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wrestrict" } */
+
+__attribute__((__malloc__)) extern void *my_malloc (__SIZE_TYPE__);
+void baz (void *);
+
+#define SIZE 32
+
+void
+foo (void)
+{
+  void *recmem = __builtin_malloc (SIZE);
+  baz (recmem);
+  while (1)
+    {
+      void *oldrecmem = recmem;
+      recmem = __builtin_malloc (SIZE);
+      if (!recmem)
+	{
+	  __builtin_free (oldrecmem);
+	  return;
+	}
+      __builtin_memcpy (recmem, oldrecmem, SIZE);	/* { dg-bogus "accessing" } */
+      baz (recmem);
+      __builtin_free (oldrecmem);
+    }
+}
+
+void
+bar (void)
+{
+  void *recmem = my_malloc (SIZE);
+  baz (recmem);
+  while (1)
+    {
+      void *oldrecmem = recmem;
+      recmem = my_malloc (SIZE);
+      if (!recmem)
+	{
+	  __builtin_free (oldrecmem);
+	  return;
+	}
+      __builtin_memcpy (recmem, oldrecmem, SIZE);	/* { dg-bogus "accessing" } */
+      baz (recmem);
+      __builtin_free (oldrecmem);
+    }
+}

	Jakub

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

* Re: [PATCH] Fix -Wrestrict SSA_NAME handling (PR c/83989)
  2018-01-25 22:20 [PATCH] Fix -Wrestrict SSA_NAME handling (PR c/83989) Jakub Jelinek
@ 2018-01-26 11:22 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2018-01-26 11:22 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, Martin Sebor, gcc-patches

On Thu, 25 Jan 2018, Jakub Jelinek wrote:

> Hi!
> 
> builtin_memref ctor for a SSA_NAME with non-NULL SSA_NAME_VAR returns
> the underlying variable, rather than just the SSA_NAME.
> Later on the code checks if the bases are equal and then compares
> corresponding offsets.
> 
> The fact that two different SSA_NAMEs have the same underlying variable
> says nothing at all whether they have the same value, as the testcase shows,
> either the SSA_NAMEs can be completely unrelated, or related, but with
> different offsets.  The code already has code to handle POINTER_PLUS_EXPR
> with a constant offset, to look through that.  Perhaps in the future there
> can be other cases we'd special case, but generally we should compare as
> bases the SSA_NAMEs, if they have the same or different base says nothing
> about them.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2018-01-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/83989
> 	* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Don't
> 	use SSA_NAME_VAR as base for SSA_NAMEs with non-NULL SSA_NAME_VAR.
> 
> 	* c-c++-common/Wrestrict-3.c: New test.
> 
> --- gcc/gimple-ssa-warn-restrict.c.jj	2018-01-17 11:54:17.000000000 +0100
> +++ gcc/gimple-ssa-warn-restrict.c	2018-01-25 14:10:26.182498552 +0100
> @@ -373,9 +373,6 @@ builtin_memref::builtin_memref (tree exp
>  		  offrange[1] += off;
>  		}
>  	    }
> -
> -	if (TREE_CODE (base) == SSA_NAME && SSA_NAME_VAR (base))
> -	  base = SSA_NAME_VAR (base);
>        }
>  
>    if (size)
> --- gcc/testsuite/c-c++-common/Wrestrict-3.c.jj	2018-01-25 14:16:01.574563425 +0100
> +++ gcc/testsuite/c-c++-common/Wrestrict-3.c	2018-01-25 14:14:39.273547506 +0100
> @@ -0,0 +1,48 @@
> +/* PR c/83989 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -Wrestrict" } */
> +
> +__attribute__((__malloc__)) extern void *my_malloc (__SIZE_TYPE__);
> +void baz (void *);
> +
> +#define SIZE 32
> +
> +void
> +foo (void)
> +{
> +  void *recmem = __builtin_malloc (SIZE);
> +  baz (recmem);
> +  while (1)
> +    {
> +      void *oldrecmem = recmem;
> +      recmem = __builtin_malloc (SIZE);
> +      if (!recmem)
> +	{
> +	  __builtin_free (oldrecmem);
> +	  return;
> +	}
> +      __builtin_memcpy (recmem, oldrecmem, SIZE);	/* { dg-bogus "accessing" } */
> +      baz (recmem);
> +      __builtin_free (oldrecmem);
> +    }
> +}
> +
> +void
> +bar (void)
> +{
> +  void *recmem = my_malloc (SIZE);
> +  baz (recmem);
> +  while (1)
> +    {
> +      void *oldrecmem = recmem;
> +      recmem = my_malloc (SIZE);
> +      if (!recmem)
> +	{
> +	  __builtin_free (oldrecmem);
> +	  return;
> +	}
> +      __builtin_memcpy (recmem, oldrecmem, SIZE);	/* { dg-bogus "accessing" } */
> +      baz (recmem);
> +      __builtin_free (oldrecmem);
> +    }
> +}
> 
> 	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-01-26 11:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-25 22:20 [PATCH] Fix -Wrestrict SSA_NAME handling (PR c/83989) Jakub Jelinek
2018-01-26 11:22 ` 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).