From patchwork Fri Jan 7 00:21:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 49674 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D83FE3857C40 for ; Fri, 7 Jan 2022 00:22:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D83FE3857C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641514952; bh=g5K0EPWHF20zn5AUbR9VZVdEveaitrhKDbhpnT1lsNw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=k2lUpeJitry0jaANhv72CZQh85iaURNdSNiDeOxdIxk3vRM1ez+cayOwg6CQ8FwrK ZlUZQ7YWMO2xW0rO26LwhDexMsIJTqBxW19rOHGyYsQsApeP+6cNQ74bvx99/VkMTV gB/HGWZTaZAqOxRNMgZE31YPo8BaXGqtV5n//Th4= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id A7DC13858017 for ; Fri, 7 Jan 2022 00:22:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7DC13858017 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-MkjkbgriPhKrlxx0ciq7Kw-1; Thu, 06 Jan 2022 19:22:00 -0500 X-MC-Unique: MkjkbgriPhKrlxx0ciq7Kw-1 Received: by mail-qk1-f198.google.com with SMTP id u17-20020a05620a431100b004765c0dc33cso3059500qko.14 for ; Thu, 06 Jan 2022 16:22:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=g5K0EPWHF20zn5AUbR9VZVdEveaitrhKDbhpnT1lsNw=; b=YT/5V2Y1A7Ur+SuZYuX95ZqRkJpTSrAfx0e8uaSbAEcO3ICgyuhMPTgjdlKhpAYaun MokA0JXbPRMeFOUR5DnPYgBST+PiCu9ZBYX+s99LNm9pxfKaDzbVakpBkhkUuUI7pA36 c1KdjPPxgiikq4i05SMlOZ4ajMAVxBeB5OdmUNdwLIM9bq0Lhi5e+Cj8Mp1t9hjY9LUQ 1xFSJWhujKMEbbSkEPjIzHXsac1PqjL6HojZ/B/mDLyfoXp0wx06YmH7ufa/Hl4oudng yIPtIJNhPLUbPsUH66uGpR1rBd6eXxggiC3ab90mPIUlaE++TYbGv4aAo9/z/10U4Cmd LTmA== X-Gm-Message-State: AOAM533NRdOB7xEsael1qsr6ptYTQvTHbqHSR1/nbYDfREWUpI7pcsYJ C+H4RoNck52+Hr/Jm8kmSZIwoPAyKbG0LN5WUQp0tSflhwAm+gWAAGOGaME3wHqCPOr8iTLedAQ Av2g8zbb2+bOlnmF72vMAL1ZEgRO4YNOA9+JYwMnvqkSlC3j5i2+xNJpH9daeRLs/8A== X-Received: by 2002:a05:622a:612:: with SMTP id z18mr54597330qta.442.1641514919487; Thu, 06 Jan 2022 16:21:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy8aFuGXZ+lFatunItoPXxKNgFPE3Sp5KWEUL3GIqcuYjh17GLenciLZ8gFfhCob9TIslmfA== X-Received: by 2002:a05:622a:612:: with SMTP id z18mr54597303qta.442.1641514918915; Thu, 06 Jan 2022 16:21:58 -0800 (PST) Received: from barrymore.redhat.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 s3sm2323785qkp.93.2022.01.06.16.21.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 16:21:57 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed 01/11] c++: don't preevaluate new-initializer Date: Thu, 6 Jan 2022 19:21:46 -0500 Message-Id: <20220107002156.2992278-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=-13.2 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Here begins a series of EH cleanup bugfixes. The preevaluation code was causing trouble with my fix for PR94041, and now I see that it's actually wrong since P0145 was adopted for C++17, mandating order of evaluation for many expressions that were previously unspecified. I don't see a need to preserve the preevaluation code for older standard modes. gcc/cp/ChangeLog: * init.c (build_new_1): Remove preevaluation code. gcc/testsuite/ChangeLog: * g++.old-deja/g++.martin/new1.C: Don't expect preeval. --- gcc/cp/init.c | 38 +++++--------------- gcc/testsuite/g++.dg/tree-ssa/stabilize1.C | 13 ------- gcc/testsuite/g++.old-deja/g++.martin/new1.C | 18 +++++----- 3 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 gcc/testsuite/g++.dg/tree-ssa/stabilize1.C base-commit: 11ce8d04f29417f2541d9b9bbfb54b3b26d7a90d diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 9d616f3f5e9..2cab4b4cdce 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3047,7 +3047,6 @@ build_new_1 (vec **placement, tree type, tree nelts, address of the first array element. This node is a VAR_DECL, and is therefore reusable. */ tree data_addr; - tree init_preeval_expr = NULL_TREE; tree orig_type = type; if (nelts) @@ -3561,7 +3560,6 @@ build_new_1 (vec **placement, tree type, tree nelts, placement delete. */ if (is_initialized) { - bool stable; bool explicit_value_init_p = false; if (*init != NULL && (*init)->is_empty ()) @@ -3587,7 +3585,6 @@ build_new_1 (vec **placement, tree type, tree nelts, init, elt_type, LOOKUP_NORMAL, complain); - stable = stabilize_init (init_expr, &init_preeval_expr); } else if (array_p) { @@ -3633,11 +3630,6 @@ build_new_1 (vec **placement, tree type, tree nelts, explicit_value_init_p, /*from_array=*/0, complain); - - /* An array initialization is stable because the initialization - of each element is a full-expression, so the temporaries don't - leak out. */ - stable = true; } else { @@ -3694,8 +3686,6 @@ build_new_1 (vec **placement, tree type, tree nelts, = replace_placeholders (TREE_OPERAND (init_expr, 1), TREE_OPERAND (init_expr, 0), &had_placeholder); - stable = (!had_placeholder - && stabilize_init (init_expr, &init_preeval_expr)); } if (init_expr == error_mark_node) @@ -3726,20 +3716,7 @@ build_new_1 (vec **placement, tree type, tree nelts, alloc_fn, complain)); - if (!cleanup) - /* We're done. */; - else if (stable) - /* This is much simpler if we were able to preevaluate all of - the arguments to the constructor call. */ - { - /* CLEANUP is compiler-generated, so no diagnostics. */ - suppress_warning (cleanup); - init_expr = build2 (TRY_CATCH_EXPR, void_type_node, - init_expr, cleanup); - /* Likewise, this try-catch is compiler-generated. */ - suppress_warning (init_expr); - } - else + if (cleanup && !processing_template_decl) /* Ack! First we allocate the memory. Then we set our sentry variable to true, and expand a cleanup that deletes the memory if sentry is true. Then we run the constructor, and @@ -3747,9 +3724,13 @@ build_new_1 (vec **placement, tree type, tree nelts, We need to do this because we allocate the space first, so if there are any temporaries with cleanups in the - constructor args and we weren't able to preevaluate them, we - need this EH region to extend until end of full-expression - to preserve nesting. */ + constructor args, we need this EH region to extend until + end of full-expression to preserve nesting. + + We used to try to evaluate the args first to avoid this, but + since C++17 [expr.new] says that "The invocation of the + allocation function is sequenced before the evaluations of + expressions in the new-initializer." */ { tree end, sentry, begin; @@ -3810,9 +3791,6 @@ build_new_1 (vec **placement, tree type, tree nelts, rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval); } - if (init_preeval_expr) - rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), init_preeval_expr, rval); - /* A new-expression is never an lvalue. */ gcc_assert (!obvalue_p (rval)); diff --git a/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C b/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C deleted file mode 100644 index 5eb0bf8d525..00000000000 --- a/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C +++ /dev/null @@ -1,13 +0,0 @@ -// PR c++/53356 -// { dg-options "-fdump-tree-gimple" } -// { dg-final { scan-tree-dump-not "= 0" "gimple" } } - -class A {}; - -struct B { - operator const A &() const; -}; - -A* cause_ICE() { - return new A(B()); -} diff --git a/gcc/testsuite/g++.old-deja/g++.martin/new1.C b/gcc/testsuite/g++.old-deja/g++.martin/new1.C index 502c4f42ad0..18eb88d7c79 100644 --- a/gcc/testsuite/g++.old-deja/g++.martin/new1.C +++ b/gcc/testsuite/g++.old-deja/g++.martin/new1.C @@ -1,5 +1,5 @@ // { dg-do run } -//Lifetime of temporaries: +//Lifetime of temporaries: //egcs 2.92 performs cleanup for temporaries inside new expressions //after the new is complete, not at the end of the full expression. @@ -71,8 +71,8 @@ void test1() func(new B(A(10).addr())); }catch(int){ } - CHECK(ctor_done==1); - CHECK(new_done==2); + CHECK(new_done==1); + CHECK(ctor_done==2); CHECK(func_done==3); CHECK(dtor_done==4); CHECK(delete_done==0); @@ -86,10 +86,10 @@ void test2() func(new B(A(10).addr())); }catch(int){ } - CHECK(ctor_done==1); - CHECK(new_done==2); + CHECK(new_done==1); + CHECK(ctor_done==0); CHECK(func_done==0); - CHECK(dtor_done==3); + CHECK(dtor_done==0); CHECK(delete_done==0); } @@ -101,11 +101,11 @@ void test3() func(new B(A(10).addr())); }catch(int){ } - CHECK(new_done==0); - CHECK(ctor_done==1); + CHECK(new_done==1); + CHECK(ctor_done==2); CHECK(func_done==0); CHECK(dtor_done==0); - CHECK(delete_done==0); + CHECK(delete_done==3); } int main()