From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5041 invoked by alias); 11 Jan 2013 10:18:23 -0000 Received: (qmail 5025 invoked by uid 22791); 11 Jan 2013 10:18:19 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Jan 2013 10:18:15 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id B5AF8A3CEE for ; Fri, 11 Jan 2013 11:18:13 +0100 (CET) Date: Fri, 11 Jan 2013 10:18:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR44061 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg00584.txt.bz2 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 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]; + }