From patchwork Tue Apr 2 21:09:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 233144 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 3A06D2C0139 for ; Wed, 3 Apr 2013 08:09:38 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=qJ978myKm1jeHWGYZmK8VapwN+PEDZ/DKIGOXiZeRr9 WpM+Jytq9YVV8/150tepZrAnSaP40Vp1CdDV+htQsnfUhqfqGudlvA6EEdj4+kfc KurAqry7fts5mvy1YWYCp6mZGcYKZTkpVY4Rr4gqxZcdH6x9r9RGf2sgteIMvooM = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=Edg8M1Dp3WS7C1xbq6DD8yBZmK0=; b=j6qb24e01p/Udij3h g/nvs90z5oYBUPg96nbKazGUo8TV5Gl7kRFBFTNU5jLH2XPSV3m7L6H29TcWYX6M SBE41kPnbHVS3GtcP04kc0qjkqskAHzIYxYHPgN1PeUKTQc0pcgFaC/2rbLodVaw /EQGYax3Uh7tpNRDC0YVUIB9Rs= Received: (qmail 10850 invoked by alias); 2 Apr 2013 21:09:28 -0000 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 Received: (qmail 10798 invoked by uid 89); 2 Apr 2013 21:09:20 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 02 Apr 2013 21:09:17 +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 r32L9Gb2002940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 2 Apr 2013 17:09:16 -0400 Received: from [10.3.113.95] (ovpn-113-95.phx2.redhat.com [10.3.113.95]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r32L9E0n004101; Tue, 2 Apr 2013 17:09:15 -0400 Message-ID: <515B48F9.5080805@redhat.com> Date: Tue, 02 Apr 2013 17:09:13 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List CC: Jakub Jelinek Subject: C++ PATCH for c++/34949 (destructor clobbers object) X-Virus-Found: No Now that Jakub has checked in support for MEM_REF clobbers, we can use that to let the front end tell the back end that nothing in an object is interesting after the destructor is complete. This should allow us to optimize away assignments to vtable pointers if the destructor doesn't use them, and so on. Tested x86_64-pc-linux-gnu, applying to trunk. commit dcad5dc2a92840dee3bf153448ed2ccb4ace3b46 Author: Jason Merrill Date: Tue Apr 2 17:05:34 2013 -0400 PR c++/34949 * decl.c (begin_destructor_body): Clobber the object in a cleanup. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 40200b0..70137f4 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13555,6 +13555,14 @@ begin_destructor_body (void) initialize_vtbl_ptrs (current_class_ptr); finish_compound_stmt (compound_stmt); + /* Insert a cleanup to let the back end know that the object is dead + when we exit the destructor, either normally or via exception. */ + tree clobber = build_constructor (current_class_type, NULL); + TREE_THIS_VOLATILE (clobber) = true; + tree exprstmt = build2 (MODIFY_EXPR, current_class_type, + current_class_ref, clobber); + finish_decl_cleanup (NULL_TREE, exprstmt); + /* And insert cleanups for our bases and members so that they will be properly destroyed if we throw. */ push_base_cleanups (); diff --git a/gcc/testsuite/g++.dg/opt/vt2.C b/gcc/testsuite/g++.dg/opt/vt2.C new file mode 100644 index 0000000..a77db38 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/vt2.C @@ -0,0 +1,24 @@ +// PR c++/34949 +// { dg-options "-O3" } +// { dg-final { scan-assembler-not "mov\[^\n\]*_ZTV" { target i?86-*-* x86_64-*-* } } } + +class Foo +{ +public: + virtual ~Foo(); +}; + +Foo::~Foo() +{ +} + + +class Bar : public Foo +{ +public: + virtual ~Bar(); +}; + +Bar::~Bar() +{ +}