public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR44061
Date: Fri, 11 Jan 2013 10:18:00 -0000	[thread overview]
Message-ID: <alpine.LNX.2.00.1301111115500.6889@zhemvz.fhfr.qr> (raw)


This fixes PR44061 by computing a false range for __builtin_constant_p
of parameters in VRP.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

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.

Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c	(revision 195085)
--- gcc/tree-vrp.c	(working copy)
*************** extract_range_basic (value_range_t *vr,
*** 3566,3573 ****
    bool sop = false;
    tree type = gimple_expr_type (stmt);
  
!   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)
--- 3566,3585 ----
    bool sop = false;
    tree type = gimple_expr_type (stmt);
  
!   /* 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)
Index: gcc/testsuite/gcc.dg/pr44061.c
===================================================================
*** gcc/testsuite/gcc.dg/pr44061.c	(revision 0)
--- gcc/testsuite/gcc.dg/pr44061.c	(working copy)
***************
*** 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];
+ }

                 reply	other threads:[~2013-01-11 10:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.00.1301111115500.6889@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).