From patchwork Sun Apr 4 00:59:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1462056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=fy+4oBpB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FCb6k5GM7z9sV5 for ; Sun, 4 Apr 2021 10:59:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F0D73851C04; Sun, 4 Apr 2021 00:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F0D73851C04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1617497987; bh=GgmeQU4SDmotpcM/LaGRlqH+cj4izI4i254tuK2+cXY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fy+4oBpB2Ve5/3x/K31pwtZd7r/y6x4OT5oMX3Xot4eDsxInx0fqHKYdsIimQWXpL SpDqrEHYVq4FFfOFNEPY3mxLF2PIsOiWGsJwGdzx/59dP90ULTCoBMTjdHO+rrwbbi U3KJ5JWU25EERoRYUxyCd6gOsHabzNVdSt1U5ygE= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id D1AB0385702E for ; Sun, 4 Apr 2021 00:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D1AB0385702E Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-591-4QVIqVyQNhGP35IceZgddw-1; Sat, 03 Apr 2021 20:59:42 -0400 X-MC-Unique: 4QVIqVyQNhGP35IceZgddw-1 Received: by mail-qk1-f199.google.com with SMTP id x11so8161696qki.22 for ; Sat, 03 Apr 2021 17:59:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=GgmeQU4SDmotpcM/LaGRlqH+cj4izI4i254tuK2+cXY=; b=rSHG6XgvkxyUI2DksyxF2pFopbiQIwLuCfgAUDe7LpUs30uEEyQ5fCri2BNHKbS09d udAu0eqnR4THCuWTPvBRR7JSafcek2AGLVpSZ6HyYOQCsUXFliLNWcBJMm8NFkz1ao2e biSkOSiPzVMQC7TsSu6lokuCPvUSO7YdLKOi01bcs7VtBbIBltMXxWaTyLHDUN5NjP2o 87dzAmoUfvi794HwaC06cwrC7N5Dqjmjk6kfoVTDxcXUDfq8wQ7AqddTX98yGpaI4zed 6e55ncTmyGSq2DcduFlEXX+lSa9Wvkx7OYsDYUDHHEg2peJQcSBne89qvYJEJcotqmST w5Vw== X-Gm-Message-State: AOAM533mXPKOY1cu42DzsaVa25L730fv6TrnGwEIwE6wuVyNeST1qTX3 JQePyPtC93U8FuhbIYIGb7T4LuFJ8FgG4d8AwMYqeEzoezj7gcOpBJfseZ9FdFv2cF7X9NGR398 gc5tWQWuyDFC/v7SNTa7AGxDnUHXGoVXNiXi8Xxf0vyxLREj21o7Zf3D7JK5KmYtDHg== X-Received: by 2002:a05:620a:1467:: with SMTP id j7mr19148169qkl.136.1617497981246; Sat, 03 Apr 2021 17:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPapJI02lq5izwJhtz3MqkimCnebfVyR35qtTmjiSaKhiPnoUdu0JaJUiL03MQ6raygvh3ow== X-Received: by 2002:a05:620a:1467:: with SMTP id j7mr19148162qkl.136.1617497980882; Sat, 03 Apr 2021 17:59:40 -0700 (PDT) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id 21sm10680889qkv.12.2021.04.03.17.59.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Apr 2021 17:59:40 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: array new initialized from a call [PR99643] Date: Sat, 3 Apr 2021 20:59:38 -0400 Message-Id: <20210404005938.772910-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-15.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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Here the get_foo() call results in a TARGET_EXPR, which we strip in massage_init_elt, but then when build_vec_init tries to use it to initialize the array element we crash because build_aggr_init expects a class rvalue to have a TARGET_EXPR. So don't strip it. The stripping was added in r206639 for PR59659, so I checked that removing it didn't significantly increase compile time or memory usage for that testcase; compile time was unaffected, memory usage increased by 0.00004%. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: PR c++/99643 * typeck2.c (massage_init_elt): Don't strip TARGET_EXPR. gcc/testsuite/ChangeLog: PR c++/99643 * g++.dg/cpp0x/initlist-new5.C: New test. --- gcc/cp/typeck2.c | 3 --- gcc/testsuite/g++.dg/cpp0x/initlist-new5.C | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-new5.C base-commit: 78cda820d6fc944e51a4885796ef442c17cceb6e diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 96421caf22e..81caed45757 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1442,9 +1442,6 @@ massage_init_elt (tree type, tree init, int nested, int flags, if (flags & LOOKUP_AGGREGATE_PAREN_INIT) new_flags |= LOOKUP_AGGREGATE_PAREN_INIT; init = digest_init_r (type, init, nested ? 2 : 1, new_flags, complain); - /* Strip a simple TARGET_EXPR when we know this is an initializer. */ - if (SIMPLE_TARGET_EXPR_P (init)) - init = TARGET_EXPR_INITIAL (init); /* When we defer constant folding within a statement, we may want to defer this folding as well. */ tree t = fold_non_dependent_init (init, complain); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-new5.C b/gcc/testsuite/g++.dg/cpp0x/initlist-new5.C new file mode 100644 index 00000000000..da54d8981d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-new5.C @@ -0,0 +1,9 @@ +// PR c++/99643 +// { dg-do compile { target c++11 } } + +struct Foo {}; +Foo get_foo(); + +int main() { + new Foo[1]{get_foo()}; +}