From patchwork Wed Mar 16 23:32:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 87318 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 C54F0B6FFB for ; Thu, 17 Mar 2011 10:32:14 +1100 (EST) Received: (qmail 7465 invoked by alias); 16 Mar 2011 23:32:12 -0000 Received: (qmail 7456 invoked by uid 22791); 16 Mar 2011 23:32:12 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Mar 2011 23:32:05 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2GNW3cQ027306 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Mar 2011 19:32:04 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p2GNW3Bk010469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Mar 2011 19:32:03 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p2GNW2Bw014836 for ; Thu, 17 Mar 2011 00:32:02 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p2GNW2SP014834 for gcc-patches@gcc.gnu.org; Thu, 17 Mar 2011 00:32:02 +0100 Date: Thu, 17 Mar 2011 00:32:02 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Ensure DEBUG_INSNs don't contain MEMs with non-canonical MEM_EXPRs (PR debug/48134) Message-ID: <20110316233202.GQ30899@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! Currently expand_debug_expr doesn't always guarantee canonical MEM_EXPRs, if MEM_EXPR isn't canonical, sometimes aliasing code ICEs on it (since recent Richard's change fortunately only if --enable-checking=yes). The following patch canonicalizes those using fold and if canonicalization isn't successful, just clears the MEM_EXPR. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 4.6.1? 2011-03-17 Jakub Jelinek PR debug/48134 * cfgexpand.c (expand_debug_expr) : Use fold to canonicalize MEM_EXPR, if it still isn't canonical afterwards, just clear MEM_EXPR. * gcc.dg/pr48134.c: New test. Jakub --- gcc/cfgexpand.c.jj 2011-03-16 18:30:12.000000000 +0100 +++ gcc/cfgexpand.c 2011-03-16 22:05:13.000000000 +0100 @@ -2712,6 +2712,8 @@ expand_debug_expr (tree exp) if (MEM_P (op0)) { + tree mem_exp; + if (mode1 == VOIDmode) /* Bitfield. */ mode1 = smallest_mode_for_size (bitsize, MODE_INT); @@ -2736,6 +2738,12 @@ expand_debug_expr (tree exp) if (op0 == orig_op0) op0 = shallow_copy_rtx (op0); set_mem_attributes (op0, exp, 0); + mem_exp = fold (exp); + if (!SSA_VAR_P (mem_exp) + && TREE_CODE (mem_exp) != MEM_REF + && TREE_CODE (mem_exp) != TARGET_MEM_REF) + mem_exp = NULL_TREE; + set_mem_expr (op0, mem_exp); } if (bitpos == 0 && mode == GET_MODE (op0)) --- gcc/testsuite/gcc.dg/pr48134.c.jj 2011-03-16 22:04:35.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr48134.c 2011-03-16 22:02:13.000000000 +0100 @@ -0,0 +1,25 @@ +/* PR debug/48134 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fstack-check=specific -fno-tree-dse -fno-tree-fre -fno-tree-loop-optimize -g" } */ + +struct S { int w, z; }; +struct T { struct S s; }; +int i; + +static inline struct S +bar (struct S x) +{ + i++; + return x; +} + +int +foo (struct T t, struct S s) +{ + struct S *c = &s; + if (i) + c = &t.s; + t.s.w = 3; + s = bar (*c); + return t.s.w; +}