From patchwork Tue Jun 8 07:02:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 54937 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 04C2FB7D66 for ; Tue, 8 Jun 2010 17:02:28 +1000 (EST) Received: (qmail 1345 invoked by alias); 8 Jun 2010 07:02:26 -0000 Received: (qmail 1138 invoked by uid 22791); 8 Jun 2010 07:02:25 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Jun 2010 07:02:19 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id A06209AC7A9 for ; Tue, 8 Jun 2010 09:02:15 +0200 (CEST) Received: by localhost (Postfix, from userid 16202) id 9A4D45641A7; Tue, 8 Jun 2010 09:02:15 +0200 (CEST) Date: Tue, 8 Jun 2010 09:02:15 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix g++.dg/torture/pr32304.C Message-ID: <20100608070215.GA12438@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) 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, the testcase: struct S { S() {} }; S f() { static S s; return s; } fails with my last ipa-pure-const changes because variable S that is TYPE_NEEDS_CONSTRCTING become read only. Old pure-const implementation never did this change because TYPE_NEEDS_CONSTRUCTIONG vars was left out of analysis. I am not too familiar with TYPE_NEEDS_CONSTRUCTING mechanism, but I think in this case S can become read only. The reason is that S is empty and there is nothing to construct. We compile the code into: S f() () { struct S D.2138; bool D.2122; int D.2130; bool retval.1; char D.2126; char * _ZGVZ1fvE1s.0; : _ZGVZ1fvE1s.0_1 = (char *) &_ZGVZ1fvE1s; D.2126_2 = *_ZGVZ1fvE1s.0_1; if (D.2126_2 == 0) goto ; else goto ; : D.2130_3 = __cxa_guard_acquire (&_ZGVZ1fvE1s); if (D.2130_3 != 0) goto ; else goto ; : __cxa_guard_release (&_ZGVZ1fvE1s); : return D.2138; } where __cxa_guard_acquire/__cxa_guard_release pair is locking the empty initialization code, at least in my understanding. Looking at places TYPE_NEEDS_CONSTRUCTING is handled in backend, I think we should have everything gimplified to level that we do not need to care about the flag. Note also that D.2138 is undefined. It is comming so from frontend while in older versions we at least used to initialize it from static s. I wonder if this is because the var is empty. Does the attached patch seem to make sense? Bootstrapped/regtested x86_64-linux. * emit-rtl.c (set_mem_attributes_minus_bitpos): Remove TYPE_NEEDS_CONSTRUCTING sanity check. Index: emit-rtl.c =================================================================== --- emit-rtl.c (revision 160379) +++ emit-rtl.c (working copy) @@ -1668,12 +1668,7 @@ set_mem_attributes_minus_bitpos (rtx ref if (base && DECL_P (base) && TREE_READONLY (base) && (TREE_STATIC (base) || DECL_EXTERNAL (base))) - { - tree base_type = TREE_TYPE (base); - gcc_assert (!(base_type && TYPE_NEEDS_CONSTRUCTING (base_type)) - || DECL_ARTIFICIAL (base)); - MEM_READONLY_P (ref) = 1; - } + MEM_READONLY_P (ref) = 1; /* If this expression uses it's parent's alias set, mark it such that we won't change it. */