OSDN Git Service

2013-02-04 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Feb 2013 15:49:18 +0000 (15:49 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Feb 2013 15:49:18 +0000 (15:49 +0000)
Backport from mainline
2012-01-11  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/44061
* tree-vrp.c (extract_range_basic): Compute zero as
value-range for __builtin_constant_p of function parameters.

* gcc.dg/pr44061.c: New testcase.

2013-01-08  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/55890
* tree-ssa-ccp.c (evaluate_stmt): Use gimple_call_builtin_class_p.

* gcc.dg/torture/pr55890-3.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@195718 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr44061.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr55890-3.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c
gcc/tree-vrp.c

index 7fbdd5a..12850c1 100644 (file)
@@ -1,6 +1,20 @@
 2013-02-04  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
+       2012-01-11  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/44061
+       * tree-vrp.c (extract_range_basic): Compute zero as
+       value-range for __builtin_constant_p of function parameters.
+
+       2013-01-08  Jakub Jelinek  <jakub@redhat.com>
+       PR middle-end/55890
+       * tree-ssa-ccp.c (evaluate_stmt): Use gimple_call_builtin_class_p.
+
+2013-02-04  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
        2012-07-04  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/53844
index 762e61c..107f5b9 100644 (file)
@@ -1,6 +1,19 @@
 2013-02-04  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
+       2012-01-11  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/44061
+       * gcc.dg/pr44061.c: New testcase.
+
+       2013-01-08  Jakub Jelinek  <jakub@redhat.com>
+       PR middle-end/55890
+       * gcc.dg/torture/pr55890-3.c: New test.
+
+2013-02-04  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
        2012-07-04  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/53844
diff --git a/gcc/testsuite/gcc.dg/pr44061.c b/gcc/testsuite/gcc.dg/pr44061.c
new file mode 100644 (file)
index 0000000..60a4260
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+int a[2];
+int foo (int q)
+{
+  if (__builtin_constant_p (q))
+    {
+      if (q == 4)
+       return a[4]; /* { dg-bogus "array subscript is above array bounds" } */
+      else
+       return a[0];
+    }
+  else
+    return a[q];
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr55890-3.c b/gcc/testsuite/gcc.dg/torture/pr55890-3.c
new file mode 100644 (file)
index 0000000..c7f77be
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+void *memmove ();
+
+void *
+bar ()
+{
+  return memmove ();
+}
index abe50dd..105c360 100644 (file)
@@ -1,6 +1,6 @@
 /* Conditional constant propagation pass for the GNU compiler.
    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010, 2011, 2012 Free Software Foundation, Inc.
+   2010, 2011, 2012, 2013 Free Software Foundation, Inc.
    Adapted from original RTL SSA-CCP by Daniel Berlin <dberlin@dberlin.org>
    Adapted to GIMPLE trees by Diego Novillo <dnovillo@redhat.com>
 
@@ -1588,7 +1588,6 @@ evaluate_stmt (gimple stmt)
       && !is_constant)
     {
       enum gimple_code code = gimple_code (stmt);
-      tree fndecl;
       val.lattice_val = VARYING;
       val.value = NULL_TREE;
       val.mask = double_int_minus_one;
@@ -1635,10 +1634,9 @@ evaluate_stmt (gimple stmt)
              || POINTER_TYPE_P (TREE_TYPE (rhs1)))
            val = bit_value_binop (code, TREE_TYPE (rhs1), rhs1, rhs2);
        }
-      else if (code == GIMPLE_CALL
-              && (fndecl = gimple_call_fndecl (stmt))
-              && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+      else if (gimple_call_builtin_class_p (stmt, BUILT_IN_NORMAL))
        {
+         tree fndecl = gimple_call_fndecl (stmt);
          switch (DECL_FUNCTION_CODE (fndecl))
            {
            case BUILT_IN_MALLOC:
index 43f661c..1496263 100644 (file)
@@ -3268,8 +3268,20 @@ extract_range_basic (value_range_t *vr, gimple stmt)
   bool sop = false;
   tree type = gimple_expr_type (stmt);
 
-  if (INTEGRAL_TYPE_P (type)
-      && gimple_stmt_nonnegative_warnv_p (stmt, &sop))
+  /* If the call is __builtin_constant_p and the argument is a
+     function parameter resolve it to false.  This avoids bogus
+     array bound warnings.
+     ???  We could do this as early as inlining is finished.  */
+  if (gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P))
+    {
+      tree arg = gimple_call_arg (stmt, 0);
+      if (TREE_CODE (arg) == SSA_NAME
+         && SSA_NAME_IS_DEFAULT_DEF (arg)
+         && TREE_CODE (SSA_NAME_VAR (arg)) == PARM_DECL)
+       set_value_range_to_null (vr, type);
+    }
+  else if (INTEGRAL_TYPE_P (type)
+          && gimple_stmt_nonnegative_warnv_p (stmt, &sop))
     set_value_range_to_nonnegative (vr, type,
                                    sop || stmt_overflow_infinity (stmt));
   else if (vrp_stmt_computes_nonzero (stmt, &sop)