public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix PR78154
@ 2016-11-16 18:49 Prathamesh Kulkarni
  2016-11-16 18:55 ` Jakub Jelinek
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Prathamesh Kulkarni @ 2016-11-16 18:49 UTC (permalink / raw)
  To: gcc Patches, Richard Biener, Martin Sebor

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Hi Richard,
Following your suggestion in PR78154, the patch checks if stmt
contains call to memmove (and friends) in gimple_stmt_nonzero_warnv_p
and returns true in that case.

Bootstrapped+tested on x86_64-unknown-linux-gnu.
Cross-testing on arm*-*-*, aarch64*-*-* in progress.
Would it be OK to commit this patch in stage-3 ?

Thanks,
Prathamesh

[-- Attachment #2: pr78154-1.txt --]
[-- Type: text/plain, Size: 2606 bytes --]

2016-11-17  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	* tree-vrp.c (gimple_str_nonzero_warnv_p): New function.
	(gimple_stmt_nonzero_warnv_p): Call gimple_str_nonzero_warnv_p.

testsuite/
	* gcc.dg/tree-ssa/pr78154.c: New test-case.

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78154.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78154.c
new file mode 100644
index 0000000..d3463f4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78154.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp-slim" } */
+
+void f (void *d, const void *s, __SIZE_TYPE__ n)
+{
+  if (__builtin_memcpy (d, s, n) == 0)
+    __builtin_abort ();
+
+  if (__builtin_memmove (d, s, n) == 0)
+    __builtin_abort ();
+
+  if (__builtin_memset (d, 0, n) == 0)
+    __builtin_abort ();
+
+  if (__builtin_strcpy (d, s) == 0)
+    __builtin_abort ();
+
+  if (__builtin_strcat (d, s) == 0)
+    __builtin_abort ();
+
+  if (__builtin_strncpy (d, s, n) == 0)
+    __builtin_abort ();
+
+  if (__builtin_strncat (d, s, n) == 0)
+    __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_abort" "evrp" } } */
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index c2a4133..b563a7f 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -1069,6 +1069,34 @@ gimple_assign_nonzero_warnv_p (gimple *stmt, bool *strict_overflow_p)
     }
 }
 
+/* Return true if STMT is known to contain call to a string-builtin function
+   that is known to return nonnull.  */
+
+static bool
+gimple_str_nonzero_warnv_p (gimple *stmt)
+{
+  if (!is_gimple_call (stmt))
+    return false;
+
+  tree fndecl = gimple_call_fndecl (stmt);
+  if (!fndecl || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
+    return false;
+
+  switch (DECL_FUNCTION_CODE (fndecl))
+    {
+      case BUILT_IN_MEMMOVE:
+      case BUILT_IN_MEMCPY:
+      case BUILT_IN_MEMSET:
+      case BUILT_IN_STRCPY:
+      case BUILT_IN_STRNCPY:
+      case BUILT_IN_STRCAT:
+      case BUILT_IN_STRNCAT:
+	return true;
+      default:
+	return false;
+    }
+}
+
 /* Return true if STMT is known to compute a non-zero value.
    If the return value is based on the assumption that signed overflow is
    undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
@@ -1097,7 +1125,7 @@ gimple_stmt_nonzero_warnv_p (gimple *stmt, bool *strict_overflow_p)
 	    lookup_attribute ("returns_nonnull",
 			      TYPE_ATTRIBUTES (gimple_call_fntype (stmt))))
 	  return true;
-	return gimple_alloca_call_p (stmt);
+	return gimple_alloca_call_p (stmt) || gimple_str_nonzero_warnv_p (stmt);
       }
     default:
       gcc_unreachable ();

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

end of thread, other threads:[~2016-11-23  9:42 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-16 18:49 Fix PR78154 Prathamesh Kulkarni
2016-11-16 18:55 ` Jakub Jelinek
2016-11-16 20:27 ` Martin Sebor
2016-11-16 21:21   ` Marc Glisse
2016-11-17  0:17     ` Martin Sebor
2016-11-17  0:39       ` Martin Sebor
2016-11-17  4:57       ` Jeff Law
2016-11-17  8:48         ` Richard Biener
2016-11-17 15:19           ` Jeff Law
2016-11-17  8:51 ` Richard Biener
2016-11-17  9:34   ` Prathamesh Kulkarni
2016-11-17  9:54     ` Richard Biener
2016-11-18 13:03       ` Prathamesh Kulkarni
2016-11-21 10:04         ` Richard Biener
2016-11-22 10:14           ` Prathamesh Kulkarni
2016-11-22 14:53             ` Richard Biener
2016-11-23  9:35               ` Prathamesh Kulkarni
2016-11-23  9:42                 ` 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).