From patchwork Wed Feb 1 00:11:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 51109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp108333wrn; Tue, 31 Jan 2023 16:12:12 -0800 (PST) X-Google-Smtp-Source: AK7set97+FYKSgOQvxrFlzQqopzgQiBme13ntTP1vCL9y6r3df+IciygB18pafonqIgMWzbx/Z+b X-Received: by 2002:a17:906:688b:b0:87b:7c1d:e02b with SMTP id n11-20020a170906688b00b0087b7c1de02bmr252995ejr.36.1675210332159; Tue, 31 Jan 2023 16:12:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675210332; cv=none; d=google.com; s=arc-20160816; b=CLxSxjcHr/+hwWNthrl3HCXpxdx3pA8C5Fhk4njrTgBaJKNz9J6Dmw2wTBIp1JaUxz LhGZXKXCaR3pb4Mma3lfTGdEWqYqnLlubcslUavHu+eif7ny/pgxzD3wk4w/M1RAs252 zbyeP2a4XxSB3rJ4EVfKzzIJzjOGmkBmsN/XbRjhem4k38lZagUD2w9qAnfix37L8P7G jeu2Pgd2c46b5AbQZNWkQnWCcTkzalZYguz74CPcila7iigjr5eQlv1RkVqwXwBF9L98 +f5X6cgZluDfg6Ya81fTIckY+KhVXA7AoMnnG9DT1l7PUUxqVl9iXYNxvZGNJJlMmvEB GrEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=z+vWQvE2SklwbSr8G/kz3lDk8FXkGVoa8/nludwmOec=; b=Xau5HEOhfFrSRW8cNocEIgctU9jo/aokWtxccQIfQKfhnEEKu1NotXex+LDuZ0tUwT FRuizTwXwWGpb1vkDRvrbKECUTsnQf1lfaRIxODT00KsUKQzQY72TicOC1ifOF144HBs 19Yj+tKY9H7vqZHQ3oSzDmnv1+gC9oNfvqomphmIrAPttX2dEBUUQmX+d4URvXQyRaL4 Nl/KRexZ07RtR/NSNs49hvpC3FhCXsTqhArCm9t3P18+/DYx5TSMrmwbCmONdfjJnZXb 87j4tp6FNPCSkYQ3UqV9+Q/5UyE4VwTtnMprpEU5nrTAEnkYA03mSPLIMzXdculGgFH7 kjag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QJIOxzeW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gh19-20020a170906e09300b0088923c701d2si8865628ejb.399.2023.01.31.16.12.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 16:12:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QJIOxzeW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20D233857C5A for ; Wed, 1 Feb 2023 00:12:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20D233857C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675210327; bh=z+vWQvE2SklwbSr8G/kz3lDk8FXkGVoa8/nludwmOec=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QJIOxzeWd8ChA1tU5IUy83+gZwjsBTzaKuGBXuXxSid6+NhOeQFDVRVvINayPn1lg j9+dcUiki74EXqsv5qNnRVtZxsvNl96845OPQ6RnuibbiiCoKaeqKAz3oROfbBUXfR ZfZ+8D1he8Vnosnnlx6l//E5SAs/9v7/m7V5AWh4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BA6873858D33 for ; Wed, 1 Feb 2023 00:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA6873858D33 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-427-lBP8BzEhO4q7YAZQK4L88Q-1; Tue, 31 Jan 2023 19:11:15 -0500 X-MC-Unique: lBP8BzEhO4q7YAZQK4L88Q-1 Received: by mail-qv1-f71.google.com with SMTP id ng1-20020a0562143bc100b004bb706b3a27so9356957qvb.20 for ; Tue, 31 Jan 2023 16:11:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=z+vWQvE2SklwbSr8G/kz3lDk8FXkGVoa8/nludwmOec=; b=5tYHcAJV6ytR3cJB32ce/N+IvI7yoMfN3TfJzjz3yZmcISiimTPuIjFt8Wk/LaSKA9 aGkjsbPH4dpf6uqOnwejM340K0GPceyKlHeKh5sGZnxu9R6dR9iIiqcKnDl5iU5x+vcr JGQYp9PAhEs+maZJweUnTfB/nVvaCl+1Lgn45SOZYkeH6JP4PJaA4TJI+34i9qKXDQh+ XpCMpaDMHJqslpj7Ic7FbM3cqCICaNUSJ/L0Rtarn7o0+NfiF4cqRWbgyRglfZnkVQwv Lx9fMZ1A7E/yPYcqBOPXhCtWQr8HUJQdnrR6q1LIoFAvror0NLIJz/o9zEyEV/ZD3e8h KJeA== X-Gm-Message-State: AO0yUKVREjPdKcv2Skp0SbKyGwaeJL5dEqlXXIu/Uz46QCjH5BPX7rVG E/coF4FMM9lu44MbvhY0XLXvGRc76Ri70s24q6GHM02lxywS+TBEf/wcPifSACfGfl/ULzmOIsX 6XqpFAI+btPD7WCC753Hbl9BLQxfOqi9roAZGJnH4Y/DZaXCG0LlGVyaff5oZQIXQIQ== X-Received: by 2002:a05:622a:58c:b0:3b9:a6be:56f6 with SMTP id c12-20020a05622a058c00b003b9a6be56f6mr8515606qtb.26.1675210274917; Tue, 31 Jan 2023 16:11:14 -0800 (PST) X-Received: by 2002:a05:622a:58c:b0:3b9:a6be:56f6 with SMTP id c12-20020a05622a058c00b003b9a6be56f6mr8515571qtb.26.1675210274459; Tue, 31 Jan 2023 16:11:14 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s39-20020a05622a1aa700b003a7e38055c9sm10826965qtc.63.2023.01.31.16.11.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 16:11:13 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: aggregate base and TARGET_EXPR_ELIDING_P [PR108559] Date: Tue, 31 Jan 2023 19:11:11 -0500 Message-Id: <20230201001111.1045847-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756585348914139166?= X-GMAIL-MSGID: =?utf-8?q?1756585348914139166?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- We also need to split up a CONSTRUCTOR in cp_genericize_init if we need to add extra copy constructor calls to deal with CWG2403. PR c++/108559 gcc/cp/ChangeLog: * cp-gimplify.cc (any_non_eliding_target_exprs): New. (cp_genericize_init): Check it. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/aggr-base13.C: New test. --- gcc/cp/cp-gimplify.cc | 22 +++++++++++++++++++--- gcc/testsuite/g++.dg/cpp1z/aggr-base13.C | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/aggr-base13.C base-commit: a9fbc6687faa09bf045c0fcee7960b7fef796fcc diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index a35cedd05cc..9929d29981a 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -893,6 +893,21 @@ omp_cxx_notice_variable (struct cp_genericize_omp_taskreg *omp_ctx, tree decl) } } +/* True if any of the element initializers in CTOR are TARGET_EXPRs that are + not expected to elide, e.g. because unsafe_copy_elision_p is true. */ + +static bool +any_non_eliding_target_exprs (tree ctor) +{ + for (const constructor_elt &e : *CONSTRUCTOR_ELTS (ctor)) + { + if (TREE_CODE (e.value) == TARGET_EXPR + && !TARGET_EXPR_ELIDING_P (e.value)) + return true; + } + return false; +} + /* If we might need to clean up a partially constructed object, break down the CONSTRUCTOR with split_nonconstant_init. Also expand VEC_INIT_EXPR at this point. If initializing TO with FROM is non-trivial, overwrite *REPLACE with @@ -904,10 +919,11 @@ cp_genericize_init (tree *replace, tree from, tree to) tree init = NULL_TREE; if (TREE_CODE (from) == VEC_INIT_EXPR) init = expand_vec_init_expr (to, from, tf_warning_or_error); - else if (flag_exceptions - && TREE_CODE (from) == CONSTRUCTOR + else if (TREE_CODE (from) == CONSTRUCTOR && TREE_SIDE_EFFECTS (from) - && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (from))) + && ((flag_exceptions + && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (from))) + || any_non_eliding_target_exprs (from))) { to = cp_stabilize_reference (to); replace_placeholders (from, to); diff --git a/gcc/testsuite/g++.dg/cpp1z/aggr-base13.C b/gcc/testsuite/g++.dg/cpp1z/aggr-base13.C new file mode 100644 index 00000000000..c4c7ee0e8f0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/aggr-base13.C @@ -0,0 +1,19 @@ +// PR c++/108559 +// { dg-do compile { target c++17 } } + +struct A { + int g = 0; + + A() {} + A(const A&) {} +}; + +struct B : A {}; + +A u() { return A{}; } + +int bug() { return B{u()}.g; } + +int main() { + return 0; +}