From patchwork Wed Dec 21 08:23:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 35297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3403522wrn; Wed, 21 Dec 2022 00:24:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXtJnjrJ82p3vKhZhV8/374D+b4k8e0vEH25tOmHx7FAc6rVoepyi47C49Gx+kf6obRbdJFc X-Received: by 2002:a17:907:cb27:b0:7f7:a985:1838 with SMTP id um39-20020a170907cb2700b007f7a9851838mr597620ejc.44.1671611057556; Wed, 21 Dec 2022 00:24:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671611057; cv=none; d=google.com; s=arc-20160816; b=of/6vLtfHs/t7jecixtKPxLWHkY52t+IQfhzDEc2Uem+EXJGnmYyArqd2P3YGRCg6G UlTB++Ax5NCjpuVHJawEpQcQ0Oasvb58CnEq5KAtBdK4Y4dtwh+vJhxiDuIg2pUcqiPo U5nYuYLemp5hif5dfY+/GbQBlPQGQZTRrEgpK0Mb0ZYjVDdBitVopSVN/6Mm8ZUgU2j3 lkVm0qfu8IBEp6/4VKmSsmsIjc+eLQKiqBkEODGBlPMkSq7IOI9Ps8hCYUMoPRIP8Cvp KMeFUmsqctRnAL7ADjJzh30FylIa+KqZve3/7egWD1ZlkWSITn3OurF7Avoc0Z6N1Rzu OVqg== 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-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=usqEnQdvw7DP2YF5WrBUEA7YuIuUGWMCSP2N3IWYMGo=; b=olNP5Hrl6aCj9s7zYhxk91WLc4SjNFgI3EoR/rd1imU1DxHPCAaoHY7ncjNHT+6Y0+ b7nUQ1nMJnVm8XI1RnnbqxXTpUDVHiRv4xDI5e7404z8E61jKlLLhyTJ/qvOy+IgnOb3 GcxWfWHpYRmnchMokfsU7iwPl/mocTUaKLdTpmeQYzHhXUaCDMZmmLxjOEzzQpftlOt8 Iw7TYzk8PmXuTA7LiEDrf6Ei0V9LiaS3qjq6UXSXMNE7jT9K7J6OfRJdd8X9Pp5PDB7g aW9bLpB8HuhYnhpUZmyIUAKuUL/3Tv22tEF2IHwxD7IwuNAmEs5KsXLihc7U3W++w4XA gHmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uDaByxuk; 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 sy27-20020a1709076f1b00b007ad8bc64c89si11939455ejc.701.2022.12.21.00.24.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 00:24:17 -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=uDaByxuk; 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 5E1F63858298 for ; Wed, 21 Dec 2022 08:24:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E1F63858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671611056; bh=usqEnQdvw7DP2YF5WrBUEA7YuIuUGWMCSP2N3IWYMGo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uDaByxukBuOBv7Sk9thOe09gf323+f9Ln1KUP8ciW2ozG9qYd7El2lw4f75JjIRbJ ei4ZKkSbEDRBqGmiMp3lc1ukiFeAqZHl2FWIfx24ebvjNzFBy9MFwqU/sWcH5En9Yf waLkguL9zK3m7nHN/Y/vcWddNJQcNWVc9QCD69FE= 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 6471D3858D1E for ; Wed, 21 Dec 2022 08:23:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6471D3858D1E Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-74-xN7GwlBlNwe7mdA4R9qmWQ-1; Wed, 21 Dec 2022 03:23:23 -0500 X-MC-Unique: xN7GwlBlNwe7mdA4R9qmWQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BAA161C008C2 for ; Wed, 21 Dec 2022 08:23:22 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D10F112132C for ; Wed, 21 Dec 2022 08:23:22 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BL8NKLD3214037 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Wed, 21 Dec 2022 09:23:20 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BL8NJ0C3214036 for gcc-patches@gcc.gnu.org; Wed, 21 Dec 2022 09:23:19 +0100 Date: Wed, 21 Dec 2022 09:23:19 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Don't try to destruct DECL_OMP_PRIVATIZED_MEMBER vars [PR108180] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SOMETLD_ARE_BAD_TLD, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1752811236328947666?= X-GMAIL-MSGID: =?utf-8?q?1752811236328947666?= Hi! DECL_OMP_PRIVATIZED_MEMBER vars are artificial vars with DECL_VALUE_EXPR of this->field used just during gimplification and omp lowering/expansion to privatize individual fields in methods when needed. As the following testcase shows, when not in templates, they were handled right, but in templates we actually called cp_finish_decl on them and that can result in their destruction, which is obviously undesirable, we should only destruct the privatized copies of them created in omp lowering. Fixed thusly. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so far. 2022-12-21 Jakub Jelinek PR c++/108180 * pt.cc (tsubst_expr): Don't call cp_finish_decl on DECL_OMP_PRIVATIZED_MEMBER vars. * testsuite/libgomp.c++/pr108180.C: New test. Jakub --- gcc/cp/pt.cc.jj 2022-12-19 11:09:13.499170642 +0100 +++ gcc/cp/pt.cc 2022-12-20 12:13:59.406097521 +0100 @@ -18895,6 +18895,11 @@ tsubst_expr (tree t, tree args, tsubst_f maybe_push_decl (decl); if (VAR_P (decl) + && DECL_LANG_SPECIFIC (decl) + && DECL_OMP_PRIVATIZED_MEMBER (decl)) + break; + + if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl) && TREE_TYPE (pattern_decl) != error_mark_node) ndecl = tsubst_decomp_names (decl, pattern_decl, args, --- libgomp/testsuite/libgomp.c++/pr108180.C.jj 2022-12-20 12:54:21.077793817 +0100 +++ libgomp/testsuite/libgomp.c++/pr108180.C 2022-12-20 12:53:04.740905961 +0100 @@ -0,0 +1,55 @@ +// PR c++/108180 +// { dg-do run } + +struct A { + A () { ++a; } + A (A &&) = delete; + A (const A &) { ++a; } + A &operator= (const A &) = delete; + A &operator= (A &&) = delete; + ~A () { --a; } + static int a; +}; +int A::a = 0; + +struct B { + A a; + template + int + foo () + { + int res = 0; + #pragma omp parallel for if(false) firstprivate(a) + for (int i = 0; i < 64; ++i) + res += i; + return res; + } + int + bar () + { + int res = 0; + #pragma omp parallel for if(false) firstprivate(a) + for (int i = 0; i < 64; ++i) + res += i; + return res; + } +}; + +int +main () +{ + { + B b; + if (b.foo<0> () != 2016) + __builtin_abort (); + } + if (A::a != 0) + __builtin_abort (); + { + B b; + if (b.bar () != 2016) + __builtin_abort (); + } + if (A::a != 0) + __builtin_abort (); +}