From patchwork Thu Oct 13 09:56:42 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: 119399 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 0DE3CB6F82 for ; Thu, 13 Oct 2011 20:58:04 +1100 (EST) Received: (qmail 18910 invoked by alias); 13 Oct 2011 09:58:00 -0000 Received: (qmail 18900 invoked by uid 22791); 13 Oct 2011 09:57:59 -0000 X-SWARE-Spam-Status: No, hits=-1.0 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; Thu, 13 Oct 2011 09:57:38 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1REI2j-0001ZX-1s from Tom_deVries@mentor.com ; Thu, 13 Oct 2011 02:57:37 -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); Thu, 13 Oct 2011 02:46:42 -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; Thu, 13 Oct 2011 10:57:35 +0100 Message-ID: <4E96B5DA.4010004@mentor.com> Date: Thu, 13 Oct 2011 11:56:42 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 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> <4E930BF4.1050008@mentor.com> <201110101750.18988.ebotcazou@adacore.com> <4E954C24.1040903@mentor.com> In-Reply-To: <4E954C24.1040903@mentor.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/12/2011 10:13 AM, Tom de Vries wrote: > On 10/10/2011 05:50 PM, Eric Botcazou wrote: >>> So, the patch for build_constant_desc does not have the desired effect. >> >> OK, too bad that we need to play this back-and-forth game with MEMs. So the >> original patch is OK (with TREE_READONLY (base) on the next line to mimic what >> is done just above and without the gcc/ prefix in the ChangeLog). If you have >> some available cycles, you can test and install the build_constant_desc change >> in the same commit, otherwise I'll do it myself. >> > > I'll include the build_constant_desc change in a bootstrap/reg-test on x86_64. > > Thanks, > - Tom No problems found in bootstrap/reg-test on x86_64. Committed. Thanks, - Tom 2011-10-13 Tom de Vries * emit-rtl.c (set_mem_attributes_minus_bitpos): Set MEM_READONLY_P for static const strings. * varasm.c (build_constant_desc): Generate the memory location of the constant using gen_const_mem. * gcc.dg/memcpy-4.c: New test. Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c (revision 179773) +++ gcc/emit-rtl.c (working copy) @@ -1696,6 +1696,12 @@ set_mem_attributes_minus_bitpos (rtx ref && !TREE_THIS_VOLATILE (base)) MEM_READONLY_P (ref) = 1; + /* Mark static const strings readonly as well. */ + if (base && TREE_CODE (base) == STRING_CST + && TREE_READONLY (base) + && TREE_STATIC (base)) + MEM_READONLY_P (ref) = 1; + /* If this expression uses it's parent's alias set, mark it such that we won't change it. */ if (component_uses_parent_alias_set (t)) Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (revision 179773) +++ 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); Index: gcc/testsuite/gcc.dg/memcpy-4.c =================================================================== --- /dev/null (new file) +++ gcc/testsuite/gcc.dg/memcpy-4.c (revision 0) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-expand" } */ + +void +f1 (char *p) +{ + __builtin_memcpy (p, "123", 3); +} + +/* { dg-final { scan-rtl-dump-times "mem/s/u" 3 "expand" { target mips*-*-* } } } */ +/* { dg-final { cleanup-rtl-dump "expand" } } */