From patchwork Wed Mar 16 18:47:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 598588 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qQL823vJgz9sR9 for ; Thu, 17 Mar 2016 05:47:30 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=yLD/KL05; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=vmudw8IEUpj1yGCEce76mUJNVUe74JVYSQFTXB7Sg011043Bnq 2PRUqzwePKYTYrfPSB7nfSzSsN+W5YCO1PZAICmy7pOOerYMC6Job7/H4aG18Obw LKke0t4wrswc0U4/VIsBmsyIBYom0cMIdvBs0EqRZBJVZ4NbZDAHRAw9w= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=b5A+cH7NK+LSHzAJqGMcKuISe3k=; b=yLD/KL05g7ZJZOZezZhd mLQTqxGVBwzOo3jzGInXS78TBmbKb6SDmkLY1dquwZzlNiffOYLeDFt+vtXkDEg5 1XgwuA1tQfUlOwyZ5JkaNZvCR0nIuQPJWMvQGxFQLYDzB6ELQaLboTtntTXDRlWr u2guYEFZ+EfGvIM1ZArJQqo= Received: (qmail 61406 invoked by alias); 16 Mar 2016 18:47:13 -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 61394 invoked by uid 89); 16 Mar 2016 18:47:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1, 13, Hx-languages-length:1611, attrs, ca X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 16 Mar 2016 18:47:11 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 3B8DC693D2 for ; Wed, 16 Mar 2016 18:47:10 +0000 (UTC) Received: from [10.3.113.138] (ovpn-113-138.phx2.redhat.com [10.3.113.138]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2GIl9I9028229 for ; Wed, 16 Mar 2016 14:47:09 -0400 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH for c++/70259 (-flifetime-dse vs. empty bases) Message-ID: <56E9AA2D.8000901@redhat.com> Date: Wed, 16 Mar 2016 14:47:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 The constructor for an empty class can't do the -flifetime-dse clobber because when the class is used as a base it might be assigned the same offset as a real base, so the clobber would mess with real data. Tested x86_64-pc-linux-gnu, applying to trunk. commit e1a5f038350d1881153d8f65359bd883f7452237 Author: Jason Merrill Date: Wed Mar 16 13:46:32 2016 -0400 PR c++/70259 * decl.c (start_preparsed_function): Don't clobber an empty base. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4ee4ccc..e783163 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14125,6 +14125,8 @@ start_preparsed_function (tree decl1, tree attrs, int flags) && (flag_lifetime_dse > 1) && DECL_CONSTRUCTOR_P (decl1) && !DECL_CLONED_FUNCTION_P (decl1) + /* Clobbering an empty base is harmful if it overlays real data. */ + && !is_empty_class (current_class_type) /* We can't clobber safely for an implicitly-defined default constructor because part of the initialization might happen before we enter the constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */ diff --git a/gcc/testsuite/g++.dg/opt/flifetime-dse5.C b/gcc/testsuite/g++.dg/opt/flifetime-dse5.C new file mode 100644 index 0000000..2c49021 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/flifetime-dse5.C @@ -0,0 +1,13 @@ +// PR c++/70259 +// { dg-options -O2 } +// { dg-do run } + +struct Empty { }; +struct A { A() : a(true) { } bool a; }; +struct B : Empty { B() : Empty() { } }; +struct C : A, B { C() : A(), B() { } }; +int main() { + C c; + if ( c.a == false ) + __builtin_abort(); +};