From patchwork Tue Jan 24 03:26:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1730839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=nH3VBf3A; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P1C7j6mKCz23gM for ; Tue, 24 Jan 2023 14:26:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83C9C38582BC for ; Tue, 24 Jan 2023 03:26:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83C9C38582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674530805; bh=MxPeR3ckZhDl+9ZyTQzUq5zlY47mWumhQHt2DMS23j8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nH3VBf3ASQgQpbjlof6lSjsvN4T/adE+XiK7tggdiwu+jr/a4oqWphCpzh51Wmnoz bEfz0iyhn+ns3OEo2qriq59lWlC4wIuBiwuJMJqRLOwswrrdx6IE7S46jc428YrB8R NZ6+vsIzHGhED540GFJwTZ5vOObtS/Lr80m+KUTo= 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 D8C913858D3C for ; Tue, 24 Jan 2023 03:26:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8C913858D3C Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-672-xsrV8oWYMDm88ReiRv4ypA-1; Mon, 23 Jan 2023 22:26:19 -0500 X-MC-Unique: xsrV8oWYMDm88ReiRv4ypA-1 Received: by mail-qv1-f72.google.com with SMTP id jh2-20020a0562141fc200b004c74bbb0affso7008678qvb.21 for ; Mon, 23 Jan 2023 19:26:19 -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=MxPeR3ckZhDl+9ZyTQzUq5zlY47mWumhQHt2DMS23j8=; b=P6D6KPiYNhgqtETeoCGcmqf5tNl8RCeaQBpmmV3qUjnikN3fK4FWzt0DVdtDAdjCWp OAOP39EcbZi8qs1n0TeZ5Vf+kI8RJQHZdQ/pjuMTeOlYl6q0fkAFAaXmuu7vvM41ciJR VlOOLzoX7zBfasUCok4e1Hi//A6MpmZVdaAXd74gc3CQKIaRRQwUOp6rySkckK4uLDJK GaVD8qszQUulG3VX42wDRzuwJ2pyXXwULpScZMmnHQivTI95H6Mf/kgHBrmLHPO0mao+ BYnZTx5ZqMLIV1fcI1q+mBd585Vx4fedeYgI/n4RCYOXt4XQ7+Ad7Ltdvt/B8dwG7w1a YP/A== X-Gm-Message-State: AFqh2kp3s4p+wVp2OaOS/2zfuNGBtFOxkVDOfSP3fHWv1eVEc8F29nYM PjuZqbFanj+CZ/zwN/yN0zY/gHJtuqSWtflUx/x/LNc/pUssJdgIT6vEFzCYV2ZPvA5pVzbYg0N 0KIUzfwPWSBIG0/1ia6lB4Zjcg+peYoe9bl6F1wYO2ac55O+OqQS95nzWoCb5CRVwWQ== X-Received: by 2002:a05:6214:8f2:b0:537:6472:a39b with SMTP id dr18-20020a05621408f200b005376472a39bmr3091438qvb.1.1674530779064; Mon, 23 Jan 2023 19:26:19 -0800 (PST) X-Google-Smtp-Source: AK7set9OkYtFbCb925V8r+MYHNL0E/y34NPmBa4MTPKoRWllqercHjWafQjQMm1SgfCMZ6VJ0BwBYQ== X-Received: by 2002:a05:6214:8f2:b0:537:6472:a39b with SMTP id dr18-20020a05621408f200b005376472a39bmr3091402qvb.1.1674530778538; Mon, 23 Jan 2023 19:26:18 -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 z80-20020a376553000000b006fa7b5ea2d1sm645346qkb.125.2023.01.23.19.26.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 19:26:17 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: TARGET_EXPR collapsing [PR107303] Date: Mon, 23 Jan 2023 22:26:14 -0500 Message-Id: <20230124032614.121085-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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- In r13-2978 I tried to eliminate TARGET_EXPR around TARGET_EXPR by discarding the outer one, but as in this testcase that breaks if the TARGET_EXPR_SLOT of the outer one is used elsewhere. But it should always be safe to strip the inner one; if its slot were reused, there would be a COMPOUND_EXPR around the TARGET_EXPR. For 107329, if we're setting *walk_subtrees, we also need to fold TARGET_EXPR_CLEANUP. PR c++/107303 PR c++/107329 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold_r) [TARGET_EXPR]: In case of double TARGET_EXPR, keep the outer one instead of the inner one. (maybe_replace_decl): New. gcc/testsuite/ChangeLog: * g++.dg/ext/builtin-shufflevector-5.C: New test. * g++.dg/init/new51.C: New test. --- gcc/cp/cp-gimplify.cc | 31 +++++++++++++++++-- .../g++.dg/ext/builtin-shufflevector-5.C | 14 +++++++++ gcc/testsuite/g++.dg/init/new51.C | 10 ++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C create mode 100644 gcc/testsuite/g++.dg/init/new51.C base-commit: 4cbc71691e47b1ca6b64feb0af678606705d2f92 diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 83ba1285bfd..92cd309e670 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -952,6 +952,28 @@ cp_genericize_target_expr (tree *stmt_p) gcc_assert (!DECL_INITIAL (slot)); } +/* Similar to if (target_expr_needs_replace) replace_decl, but TP is the + TARGET_EXPR_INITIAL, and this also updates *_SLOT. We need this extra + replacement when cp_folding TARGET_EXPR to preserve the invariant that + AGGR_INIT_EXPR_SLOT agrees with the enclosing TARGET_EXPR_SLOT. */ + +bool +maybe_replace_decl (tree *tp, tree decl, tree replacement) +{ + if (!*tp || !VOID_TYPE_P (TREE_TYPE (*tp))) + return false; + tree t = *tp; + while (TREE_CODE (t) == COMPOUND_EXPR) + t = TREE_OPERAND (t, 1); + if (TREE_CODE (t) == AGGR_INIT_EXPR) + replace_decl (&AGGR_INIT_EXPR_SLOT (t), decl, replacement); + else if (TREE_CODE (t) == VEC_INIT_EXPR) + replace_decl (&VEC_INIT_EXPR_SLOT (t), decl, replacement); + else + replace_decl (tp, decl, replacement); + return true; +} + /* Genericization context. */ struct cp_genericize_data @@ -1116,15 +1138,18 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_) cp_genericize_target_expr (stmt_p); /* Folding might replace e.g. a COND_EXPR with a TARGET_EXPR; in - that case, use it in place of this one. */ + that case, strip it in favor of this one. */ if (tree &init = TARGET_EXPR_INITIAL (stmt)) { cp_walk_tree (&init, cp_fold_r, data, NULL); + cp_walk_tree (&TARGET_EXPR_CLEANUP (stmt), cp_fold_r, data, NULL); *walk_subtrees = 0; if (TREE_CODE (init) == TARGET_EXPR) { - TARGET_EXPR_ELIDING_P (init) = TARGET_EXPR_ELIDING_P (stmt); - *stmt_p = init; + tree sub = TARGET_EXPR_INITIAL (init); + maybe_replace_decl (&sub, TARGET_EXPR_SLOT (init), + TARGET_EXPR_SLOT (stmt)); + init = sub; } } break; diff --git a/gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C new file mode 100644 index 00000000000..06472b8d86b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-5.C @@ -0,0 +1,14 @@ +// PR c++/107303 +// { dg-options "-Wno-psabi" } + +typedef __attribute__((__vector_size__ (2))) unsigned short U; +typedef __attribute__((__vector_size__ (8))) unsigned short V; + +U u0, u1, u2; +V v; + +void +foo (void) +{ + u0 *= +__builtin_shufflevector (__builtin_shufflevector (u1, v, 3, 1), u2, 0); +} diff --git a/gcc/testsuite/g++.dg/init/new51.C b/gcc/testsuite/g++.dg/init/new51.C new file mode 100644 index 00000000000..d8b336476d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new51.C @@ -0,0 +1,10 @@ +// PR c++/107329 + +struct RexxClass { + void *operator new(unsigned long, unsigned long, const char *, RexxClass *, + RexxClass *); + void operator delete(void *, unsigned long, const char *, RexxClass *, + RexxClass *); + RexxClass(); +}; +void createInstance() { new (sizeof(RexxClass), "", 0, 0) RexxClass; }