Fix host_size_t_cst_p predicat
authorMartin Liska <mliska@suse.cz>
Wed, 2 Nov 2016 09:56:04 +0000 (10:56 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 2 Nov 2016 09:56:04 +0000 (09:56 +0000)
* fold-const-call.c (host_size_t_cst_p): Test whether
t is convertible to size_t.
* gcc.dg/tree-ssa/builtins-folding-gimple-ub.c (main): Add
test case.

From-SVN: r241780

gcc/ChangeLog
gcc/fold-const-call.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c

index ba76566..1b74bd2 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-02  Martin Liska  <mliska@suse.cz>
+
+       * fold-const-call.c (host_size_t_cst_p): Test whether
+       t is convertible to size_t.
+
 2016-11-02  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR tree-optimization/78170
index 05a15f9..1b3a755 100644 (file)
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "case-cfn-macros.h"
 #include "tm.h" /* For C[LT]Z_DEFINED_AT_ZERO.  */
 #include "builtins.h"
+#include "gimple-expr.h"
 
 /* Functions that test for certain constant types, abstracting away the
    decision about whether to check for overflow.  */
@@ -57,7 +58,8 @@ complex_cst_p (tree t)
 static inline bool
 host_size_t_cst_p (tree t, size_t *size_out)
 {
-  if (integer_cst_p (t)
+  if (types_compatible_p (size_type_node, TREE_TYPE (t))
+      && integer_cst_p (t)
       && wi::min_precision (t, UNSIGNED) <= sizeof (size_t) * CHAR_BIT)
     {
       *size_out = tree_to_uhwi (t);
index c06c315..38668b7 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-02  Martin Liska  <mliska@suse.cz>
+
+       * gcc.dg/tree-ssa/builtins-folding-gimple-ub.c (main): Add
+       test case.
+
 2016-11-02  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR tree-optimization/78170
index df0ede2..e1658d1 100644 (file)
@@ -17,6 +17,10 @@ main (void)
   if (__builtin_memchr (foo1, 'x', 1000)) /* Not folded away.  */
     __builtin_abort ();
 
+  /* STRNCMP.  */
+  if (strncmp ("a", "b", -1)) /* { dg-warning "implicit declaration of function" } */
+    __builtin_abort ();
+
   return 0;
 }