aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2019-09-11 11:16:54 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2019-09-11 11:16:54 +0000
commit46dfa8ad6c18feb45d35734eae38798edb7c38cd (patch)
tree827937264473170139a5e038754a1bbde166a92c
parent0a237a94c206b53eb73baad2d75fbcca518df65e (diff)
downloadgcc-46dfa8ad6c18feb45d35734eae38798edb7c38cd.zip
gcc-46dfa8ad6c18feb45d35734eae38798edb7c38cd.tar.gz
gcc-46dfa8ad6c18feb45d35734eae38798edb7c38cd.tar.bz2
re PR tree-optimization/90387 (__builtin_constant_p and -Warray-bounds warnings)
2019-09-11 Richard Biener <rguenther@suse.de> PR tree-optimization/90387 * vr-values.c (vr_values::extract_range_basic): After inlining simplify non-constant __builtin_constant_p to false. * gcc.dg/Warray-bounds-44.c: New testcase. From-SVN: r275639
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/Warray-bounds-44.c23
-rw-r--r--gcc/vr-values.c11
4 files changed, 36 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3452012..21c247b8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-09-11 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/90387
+ * vr-values.c (vr_values::extract_range_basic): After inlining
+ simplify non-constant __builtin_constant_p to false.
+
2019-09-11 Eric Botcazou <ebotcazou@adacore.com>
PR rtl-optimization/89795
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cd9821e..940be7f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-09-11 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/90387
+ * gcc.dg/Warray-bounds-44.c: New testcase.
+
2019-09-11 Eric Botcazou <ebotcazou@adacore.com>
* gcc.target/sparc/20161111-1.c: XFAIL redundant zero-extension test.
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-44.c b/gcc/testsuite/gcc.dg/Warray-bounds-44.c
new file mode 100644
index 0000000..709d004
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-44.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Warray-bounds" } */
+
+int foo(unsigned int state, unsigned char * p, unsigned int p_len)
+{
+ static char const pattern[] = "abcd";
+ static unsigned const pattern_length = sizeof(pattern) - 1;
+
+ if (p_len == 1) {
+ return state;
+ }
+
+ if (state < pattern_length &&
+ p_len == (pattern_length - state) &&
+ (!__builtin_constant_p(p_len) ?
+ __builtin_memcmp(p, pattern + state, p_len) :
+ ((unsigned char*)p)[6] == ((unsigned char*)pattern + state)[6] /* { dg-bogus "array bounds" } */
+ )) {
+
+ return 4;
+ }
+ return 1;
+}
diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index 256cae7..0ebb6e3 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -1124,15 +1124,8 @@ vr_values::extract_range_basic (value_range *vr, gimple *stmt)
switch (cfn)
{
case CFN_BUILT_IN_CONSTANT_P:
- /* 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. */
- 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
- && cfun->after_inlining)
+ /* Resolve calls to __builtin_constant_p after inlining. */
+ if (cfun->after_inlining)
{
vr->set_zero (type);
vr->equiv_clear ();