From patchwork Mon Oct 10 15:15:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 118754 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 62736B7182 for ; Tue, 11 Oct 2011 02:15:46 +1100 (EST) Received: (qmail 15932 invoked by alias); 10 Oct 2011 15:15:42 -0000 Received: (qmail 15920 invoked by uid 22791); 10 Oct 2011 15:15:40 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 10 Oct 2011 15:15:21 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1RDHZY-0001f4-3D from Tom_deVries@mentor.com ; Mon, 10 Oct 2011 08:15:20 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 10 Oct 2011 08:04:39 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Mon, 10 Oct 2011 16:15:18 +0100 Message-ID: <4E930BF4.1050008@mentor.com> Date: Mon, 10 Oct 2011 17:15:00 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15 MIME-Version: 1.0 To: Eric Botcazou CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH] Mark static const strings as read-only. References: <4E92B854.5070208@mentor.com> <201110101544.50667.ebotcazou@adacore.com> In-Reply-To: <201110101544.50667.ebotcazou@adacore.com> 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 On 10/10/2011 03:44 PM, Eric Botcazou wrote: >> The patch makes sure that the src_mem computed here in >> expand_builtin_memcpy is marked as MEM_READONLY_P: >> ... >> src_mem = get_memory_rtx (src, len); >> ... >> >> build and reg-tested on i686, arm, and mips. >> >> OK for trunk? > > Do you get the same result by calling gen_const_mem from build_constant_desc > instead of gen_rtx_MEM? If so, this would be better I think. > I tried the patch that you describe: ... ... The src_mem in expand_builtin_memcpy is generated in get_memory_rtx: ... static rtx get_memory_rtx (tree exp, tree len) { tree orig_exp = exp; rtx addr, mem; HOST_WIDE_INT off; /* When EXP is not resolved SAVE_EXPR, MEM_ATTRS can be still derived from its expression, for expr->a.b only .a.b is recorded. */ if (TREE_CODE (exp) == SAVE_EXPR && !SAVE_EXPR_RESOLVED_P (exp)) exp = TREE_OPERAND (exp, 0); addr = expand_expr (orig_exp, NULL_RTX, ptr_mode, EXPAND_NORMAL); mem = gen_rtx_MEM (BLKmode, memory_address (BLKmode, addr)); ... With the patch for build_constant_desc, a mem with MEM_READONLY_P set (/u) is generated in expand_expr_constant during expand_expr: ... (mem/s/u/c:BLK (symbol_ref/f:SI ("*$LC0") [flags 0x2] ) [1 S4 A32]) ... but the expand_expr returns this: ... (symbol_ref/f:SI ("*$LC0") [flags 0x2] ) ... The subsequent gen_rtx_MEM generates this: ... (mem:BLK (lo_sum:SI (reg:SI 195) (symbol_ref/f:SI ("*$LC0") [flags 0x2] )) [0 A8]) ... and after set_mem_attributes it looks like this: ... (mem/s/c:BLK (lo_sum:SI (reg:SI 195) (symbol_ref/f:SI ("*$LC0") [flags 0x2] )) [0 S4 A32]) ... So, the patch for build_constant_desc does not have the desired effect. Thanks, - Tom Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (revision 179662) +++ gcc/varasm.c (working copy) @@ -3119,7 +3119,7 @@ build_constant_desc (tree exp) SET_SYMBOL_REF_DECL (symbol, decl); TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1; - rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol); + rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol); set_mem_attributes (rtl, exp, 1); set_mem_alias_set (rtl, 0); set_mem_alias_set (rtl, const_alias_set);