From patchwork Wed Jan 9 18:04:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 210810 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 939C62C0172 for ; Thu, 10 Jan 2013 05:04:37 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1358359478; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=affGwsU dgn+iYpsJYIK23dzx8u4=; b=azfaH1ZX7b1cqvjAl8/JCc8MU4fi+H8zcYMgPCj UmylnIFwNOUPb0OMZKPHRcAW2Vklwj2aMt5ujHy5eN0j5T1DZ3FAH/cGyhei7mdH SszjbV4NcNWtSBX+1LYOIh9lDEwwVYzx6AthQh5tPzOFSUOyeKqKJUxTfXA9OOaV qoms= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=bF64fhD2gkzuUe1Q++BeFb5MYC3mc10hDoFjW6x+lankG9JDBaeJj9iAkWn8yo CWzPJvAGGRhKCS/ILPOZKJZ0mXCKYM4/iAXGdk6d2kUpWQTYjMcfwlraXHiB133T Q/L313GIBj1OKIPrpiHiPkwcGRzarh3Uh7c4IJPnJo7T8=; Received: (qmail 13416 invoked by alias); 9 Jan 2013 18:04:20 -0000 Received: (qmail 13402 invoked by uid 22791); 9 Jan 2013 18:04:17 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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, 09 Jan 2013 18:04:07 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r09I46bF020406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Jan 2013 13:04:06 -0500 Received: from [10.3.113.88] (ovpn-113-88.phx2.redhat.com [10.3.113.88]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r09I46El025183 for ; Wed, 9 Jan 2013 13:04:06 -0500 Message-ID: <50EDB115.10507@redhat.com> Date: Wed, 09 Jan 2013 13:04:05 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55893 (segfault running destructor on rodata) 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 My fix for PR 49673 made it so that objects with constant initialization semantics through constexpr can go into rodata now. But objects with non-trivial destruction semantics still need to go into writable data so that the destructor can modify the object. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit f7142c9ff05259adbda2cb5797088b6a2c281ad9 Author: Jason Merrill Date: Wed Jan 9 11:44:13 2013 -0500 PR c++/55893 * decl.c (cp_finish_decl): Clear TREE_READONLY if the variable needs destruction. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9640824..c3622ec 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6417,6 +6417,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, } else if (was_readonly) TREE_READONLY (decl) = 1; + + /* Likewise if it needs destruction. */ + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) + TREE_READONLY (decl) = 0; } make_rtl_for_nonlocal_decl (decl, init, asmspec); diff --git a/gcc/testsuite/g++.dg/init/const9.C b/gcc/testsuite/g++.dg/init/const9.C new file mode 100644 index 0000000..ba1dfd4 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/const9.C @@ -0,0 +1,12 @@ +// PR c++/55893 +// { dg-final { scan-assembler-not "rodata" } } + +struct foo +{ + virtual ~foo (); +}; + +int main () +{ + static const foo tmp; +}