https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90387

--- Comment #3 from rguenther at suse dot de <rguenther at suse dot de> ---
On Fri, 10 May 2019, JunMa at linux dot alibaba.com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90387
> 
> JunMa <JunMa at linux dot alibaba.com> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |JunMa at linux dot 
> alibaba.com
> 
> --- Comment #2 from JunMa <JunMa at linux dot alibaba.com> ---
> VRP tries to fold builtin_constant_p when its argument is a function 
> parameter.
> builtin_constant_p should be removed as dead stmt in this case no matter  "#if
> 1 " or "#if 0", since p_len is function parameter. 
> 
> When "#if 1" turns true, vrp pass inserts ASSERT_EXPR to infer value range of
> p_len, this changes argument of builtin_constant_p from function parameter to
> result of ASSERT_EXPR which breaks the rule.

Whether the argument is a function parameter or not is of course
somewhat artificial.  I have argued the code should be

diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index 0e10aca92bb..d1d9756c134 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -1075,15 +1075,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_null (type);
              return;

Reply via email to