public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gimple: Ignore *0 = {CLOBBER} in path isolation [PR96722]
@ 2020-08-24 21:37 Jakub Jelinek
  2020-08-25  7:10 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-08-24 21:37 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

Clobbers of MEM_REF with NULL address are just fancy nops, something we just
ignore and don't emit any code for it (ditto for other clobbers), they just
mark end of life on something, so we shouldn't infer from those that there
is some UB.

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

2020-08-24  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/96722
	* gimple.c (infer_nonnull_range): Formatting fix.
	(infer_nonnull_range_by_dereference): Return false for clobber stmts.

	* g++.dg/opt/pr96722.C: New test.

--- gcc/gimple.c.jj	2020-08-03 22:54:51.417531677 +0200
+++ gcc/gimple.c	2020-08-24 13:23:22.082312349 +0200
@@ -2917,8 +2917,8 @@ check_loadstore (gimple *, tree op, tree
 bool
 infer_nonnull_range (gimple *stmt, tree op)
 {
-  return infer_nonnull_range_by_dereference (stmt, op)
-    || infer_nonnull_range_by_attribute (stmt, op);
+  return (infer_nonnull_range_by_dereference (stmt, op)
+	  || infer_nonnull_range_by_attribute (stmt, op));
 }
 
 /* Return true if OP can be inferred to be non-NULL after STMT
@@ -2930,7 +2930,8 @@ infer_nonnull_range_by_dereference (gimp
      non-NULL if -fdelete-null-pointer-checks is enabled.  */
   if (!flag_delete_null_pointer_checks
       || !POINTER_TYPE_P (TREE_TYPE (op))
-      || gimple_code (stmt) == GIMPLE_ASM)
+      || gimple_code (stmt) == GIMPLE_ASM
+      || gimple_clobber_p (stmt))
     return false;
 
   if (walk_stmt_load_store_ops (stmt, (void *)op,
--- gcc/testsuite/g++.dg/opt/pr96722.C.jj	2020-08-24 13:24:45.357132323 +0200
+++ gcc/testsuite/g++.dg/opt/pr96722.C	2020-08-24 13:25:06.224836626 +0200
@@ -0,0 +1,20 @@
+// PR tree-optimization/96722
+// { dg-do run }
+// { dg-options "-O2" }
+
+struct S { int s; ~S () {} };
+
+void
+foo (S *a)
+{
+  if (a)
+    return;
+  a->~S ();
+}
+
+int
+main ()
+{
+  S s;
+  foo (&s);
+}

	Jakub


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

* Re: [PATCH] gimple: Ignore *0 = {CLOBBER} in path isolation [PR96722]
  2020-08-24 21:37 [PATCH] gimple: Ignore *0 = {CLOBBER} in path isolation [PR96722] Jakub Jelinek
@ 2020-08-25  7:10 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2020-08-25  7:10 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, gcc-patches

On Mon, 24 Aug 2020, Jakub Jelinek wrote:

> Hi!
> 
> Clobbers of MEM_REF with NULL address are just fancy nops, something we just
> ignore and don't emit any code for it (ditto for other clobbers), they just
> mark end of life on something, so we shouldn't infer from those that there
> is some UB.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2020-08-24  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/96722
> 	* gimple.c (infer_nonnull_range): Formatting fix.
> 	(infer_nonnull_range_by_dereference): Return false for clobber stmts.
> 
> 	* g++.dg/opt/pr96722.C: New test.
> 
> --- gcc/gimple.c.jj	2020-08-03 22:54:51.417531677 +0200
> +++ gcc/gimple.c	2020-08-24 13:23:22.082312349 +0200
> @@ -2917,8 +2917,8 @@ check_loadstore (gimple *, tree op, tree
>  bool
>  infer_nonnull_range (gimple *stmt, tree op)
>  {
> -  return infer_nonnull_range_by_dereference (stmt, op)
> -    || infer_nonnull_range_by_attribute (stmt, op);
> +  return (infer_nonnull_range_by_dereference (stmt, op)
> +	  || infer_nonnull_range_by_attribute (stmt, op));
>  }
>  
>  /* Return true if OP can be inferred to be non-NULL after STMT
> @@ -2930,7 +2930,8 @@ infer_nonnull_range_by_dereference (gimp
>       non-NULL if -fdelete-null-pointer-checks is enabled.  */
>    if (!flag_delete_null_pointer_checks
>        || !POINTER_TYPE_P (TREE_TYPE (op))
> -      || gimple_code (stmt) == GIMPLE_ASM)
> +      || gimple_code (stmt) == GIMPLE_ASM
> +      || gimple_clobber_p (stmt))
>      return false;
>  
>    if (walk_stmt_load_store_ops (stmt, (void *)op,
> --- gcc/testsuite/g++.dg/opt/pr96722.C.jj	2020-08-24 13:24:45.357132323 +0200
> +++ gcc/testsuite/g++.dg/opt/pr96722.C	2020-08-24 13:25:06.224836626 +0200
> @@ -0,0 +1,20 @@
> +// PR tree-optimization/96722
> +// { dg-do run }
> +// { dg-options "-O2" }
> +
> +struct S { int s; ~S () {} };
> +
> +void
> +foo (S *a)
> +{
> +  if (a)
> +    return;
> +  a->~S ();
> +}
> +
> +int
> +main ()
> +{
> +  S s;
> +  foo (&s);
> +}
> 
> 	Jakub
> 
> 

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

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

end of thread, other threads:[~2020-08-25  7:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 21:37 [PATCH] gimple: Ignore *0 = {CLOBBER} in path isolation [PR96722] Jakub Jelinek
2020-08-25  7:10 ` 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).