From patchwork Wed Jun 16 21:29:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 55939 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 82632B7D66 for ; Thu, 17 Jun 2010 07:29:14 +1000 (EST) Received: (qmail 9946 invoked by alias); 16 Jun 2010 21:29:13 -0000 Received: (qmail 9937 invoked by uid 22791); 16 Jun 2010 21:29:12 -0000 X-SWARE-Spam-Status: No, hits=-3.4 required=5.0 tests=AWL, BAYES_00, T_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; Wed, 16 Jun 2010 21:29:07 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 7C26D86EE4 for ; Wed, 16 Jun 2010 23:29:04 +0200 (CEST) Date: Wed, 16 Jun 2010 23:29:04 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH][mem-ref2] Fix some warning regressions Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the branch. Richard. 2010-06-16 Richard Guenther * tree-ssa.c (warn_uninitialized_var): Handle MEM_REF. 2010-06-16 Richard Guenther * tree-vrp.c (check_array_ref): Handle MEM_REF. (search_for_addr_array): Likewise. (check_array_bounds): Likewise. Index: gcc/tree-vrp.c =================================================================== *** gcc/tree-vrp.c (revision 160824) --- gcc/tree-vrp.c (working copy) *************** check_array_ref (location_t location, tr *** 5071,5079 **** /* Accesses to trailing arrays via pointers may access storage beyond the types array bounds. */ base = get_base_address (ref); ! if (base ! && (INDIRECT_REF_P (base) ! || TREE_CODE (base) == MEM_REF)) { tree cref, next = NULL_TREE; --- 5071,5077 ---- /* Accesses to trailing arrays via pointers may access storage beyond the types array bounds. */ base = get_base_address (ref); ! if (base && TREE_CODE (base) == MEM_REF) { tree cref, next = NULL_TREE; *************** search_for_addr_array (tree t, location_ *** 5172,5177 **** --- 5170,5220 ---- t = TREE_OPERAND (t, 0); } while (handled_component_p (t)); + + if (TREE_CODE (t) == MEM_REF + && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR + && !TREE_NO_WARNING (t)) + { + tree tem = TREE_OPERAND (TREE_OPERAND (t, 0), 0); + tree low_bound, up_bound, el_sz; + double_int idx; + if (TREE_CODE (TREE_TYPE (tem)) != ARRAY_TYPE + || TREE_CODE (TREE_TYPE (TREE_TYPE (tem))) == ARRAY_TYPE + || !TYPE_DOMAIN (TREE_TYPE (tem))) + return; + + low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (tem))); + up_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tem))); + el_sz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (tem))); + if (!low_bound + || TREE_CODE (low_bound) != INTEGER_CST + || !up_bound + || TREE_CODE (up_bound) != INTEGER_CST + || !el_sz + || TREE_CODE (el_sz) != INTEGER_CST) + return; + + idx = mem_ref_offset (t); + idx = double_int_sdiv (idx, tree_to_double_int (el_sz), TRUNC_DIV_EXPR); + if (double_int_scmp (idx, double_int_zero) < 0) + { + warning_at (location, OPT_Warray_bounds, + "array subscript is below array bounds"); + TREE_NO_WARNING (t) = 1; + } + else if (double_int_scmp (idx, + double_int_add + (double_int_add + (tree_to_double_int (up_bound), + double_int_neg + (tree_to_double_int (low_bound))), + double_int_one)) > 0) + { + warning_at (location, OPT_Warray_bounds, + "array subscript is above array bounds"); + TREE_NO_WARNING (t) = 1; + } + } } /* walk_tree() callback that checks if *TP is *************** check_array_bounds (tree *tp, int *walk_ *** 5200,5206 **** if (TREE_CODE (t) == ARRAY_REF) check_array_ref (location, t, false /*ignore_off_by_one*/); ! if (TREE_CODE (t) == INDIRECT_REF || (TREE_CODE (t) == RETURN_EXPR && TREE_OPERAND (t, 0))) search_for_addr_array (TREE_OPERAND (t, 0), location); --- 5243,5249 ---- if (TREE_CODE (t) == ARRAY_REF) check_array_ref (location, t, false /*ignore_off_by_one*/); ! if (TREE_CODE (t) == MEM_REF || (TREE_CODE (t) == RETURN_EXPR && TREE_OPERAND (t, 0))) search_for_addr_array (TREE_OPERAND (t, 0), location); Index: gcc/tree-ssa.c =================================================================== --- gcc/tree-ssa.c (revision 160824) +++ gcc/tree-ssa.c (working copy) @@ -1650,8 +1650,9 @@ warn_uninitialized_var (tree *tp, int *w /* We do not care about LHS. */ if (wi->is_lhs) { - /* Except for operands of INDIRECT_REF. */ - if (!INDIRECT_REF_P (t)) + /* Except for operands of dereferences. */ + if (!INDIRECT_REF_P (t) + && TREE_CODE (t) != MEM_REF) return NULL_TREE; t = TREE_OPERAND (t, 0); }