]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2012-01-11 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Jan 2013 10:20:02 +0000 (10:20 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Jan 2013 10:20:02 +0000 (10:20 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@195103 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr44061.c [new file with mode: 0644]
gcc/tree-vrp.c

index be407d49ae9a7705512b702af1936d3bf5d9e193..9cbce45312b8234f321fe20940271b0f1ea47e73 100644 (file)
@@ -1,3 +1,9 @@
+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-10  Richard Sandiford  <rdsandiford@googlemail.com>
 
        Update copyright years
index 25a44f0790c90364918f83acfe17ec4f3e469cc1..df0378f1d123a834de99021781c097a0b76f8a29 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-11  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/44061
+       * gcc.dg/pr44061.c: New testcase.
+
 2013-01-10  Richard Sandiford  <rdsandiford@googlemail.com>
 
        Update copyright years
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];
+}
index 38cf7ddca03037cdd86db96d2fd7ca59ab9a8f66..e902f6eb33d9c72f16eb7ca6ff7fa6271aa96bc2 100644 (file)
@@ -3565,8 +3565,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)