From patchwork Thu Mar 19 11:30:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1258117 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; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=IjzyVBC1; 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 48jl7w6nDyz9sPk for ; Thu, 19 Mar 2020 22:30:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4058385E830; Thu, 19 Mar 2020 11:30:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4058385E830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584617416; bh=HSsmKjPO4Dd+ft/sAEhgtkLDI/AWnGWZ/J7dpmSMBJI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IjzyVBC1R6C5PjqBdxPf6A0/h847jtVBKQYJlWWg2YVmJKwNrJH9zoebUkl9GAzCh sled5TO7YQmShHW/wRTSYHN2ZsR0mnEFuHB+9W27SA/chBQKZnO6IG7gpXSpesgnUY 9+KOG9/pnakp+keIem4u/Wa/Du0+tCzLAzVvSa1k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by sourceware.org (Postfix) with ESMTP id 627DD385C017 for ; Thu, 19 Mar 2020 11:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 627DD385C017 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-ZTKN6H_1OseK0QeoeXWBmA-1; Thu, 19 Mar 2020 07:30:12 -0400 X-MC-Unique: ZTKN6H_1OseK0QeoeXWBmA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35749477 for ; Thu, 19 Mar 2020 11:30:11 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCD6D91290; Thu, 19 Mar 2020 11:30:10 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 02JBU8th030074; Thu, 19 Mar 2020 12:30:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 02JBU8wo030073; Thu, 19 Mar 2020 12:30:08 +0100 Date: Thu, 19 Mar 2020 12:30:08 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] c++: Fix up handling of captured vars in lambdas in OpenMP clauses [PR93931] Message-ID: <20200319113008.GQ2156@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-10.2 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS 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: Jakub Jelinek via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! Without the parser.c change we were ICEing on the testcase, because while the uses of the captured vars inside of the constructs were replaced with capture proxy decls, we didn't do that for decls in OpenMP clauses. With that fixed, we don't ICE anymore, but the testcase is miscompiled and FAILs at runtime. This is because the capture proxy decls have DECL_VALUE_EXPR and during gimplification we were gimplifying those to their DECL_VALUE_EXPRs. That is fine for shared vars, but for privatized ones we must not do that. So that is what the cp-gimplify.c changes do. Had to add a DECL_CONTEXT check before calling is_capture_proxy because some VAR_DECLs don't have DECL_CONTEXT set (yet) and is_capture_proxy relies on that being non-NULL always. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2020-03-19 Jakub Jelinek PR c++/93931 * parser.c (cp_parser_omp_var_list_no_open): Call process_outer_var_ref on outer_automatic_var_p decls. * cp-gimplify.c (cxx_omp_disregard_value_expr): Return true also for capture proxy decls. * testsuite/libgomp.c++/pr93931.C: New test. Jakub --- gcc/cp/parser.c.jj 2020-03-19 10:20:28.621837665 +0100 +++ gcc/cp/parser.c 2020-03-19 11:17:25.204683731 +0100 @@ -34059,6 +34059,8 @@ cp_parser_omp_var_list_no_open (cp_parse token->location); } } + if (outer_automatic_var_p (decl)) + decl = process_outer_var_ref (decl, tf_warning_or_error); if (decl == error_mark_node) ; else if (kind != 0) --- gcc/cp/cp-gimplify.c.jj 2020-03-19 10:20:28.276842716 +0100 +++ gcc/cp/cp-gimplify.c 2020-03-19 11:41:01.101925656 +0100 @@ -2260,12 +2260,17 @@ cxx_omp_finish_clause (tree c, gimple_se bool cxx_omp_disregard_value_expr (tree decl, bool shared) { - return !shared - && VAR_P (decl) - && DECL_HAS_VALUE_EXPR_P (decl) - && DECL_ARTIFICIAL (decl) - && DECL_LANG_SPECIFIC (decl) - && DECL_OMP_PRIVATIZED_MEMBER (decl); + if (shared) + return false; + if (VAR_P (decl) + && DECL_HAS_VALUE_EXPR_P (decl) + && DECL_ARTIFICIAL (decl) + && DECL_LANG_SPECIFIC (decl) + && DECL_OMP_PRIVATIZED_MEMBER (decl)) + return true; + if (VAR_P (decl) && DECL_CONTEXT (decl) && is_capture_proxy (decl)) + return true; + return false; } /* Fold expression X which is used as an rvalue if RVAL is true. */ --- libgomp/testsuite/libgomp.c++/pr93931.C.jj 2020-03-19 11:43:51.839420252 +0100 +++ libgomp/testsuite/libgomp.c++/pr93931.C 2020-03-19 11:38:22.097258893 +0100 @@ -0,0 +1,120 @@ +// PR c++/93931 +// { dg-do run } +// { dg-options "-O2 -std=c++14" } + +extern "C" void abort (); + +void +sink (int &x) +{ + int *volatile p; + p = &x; + (*p)++; +} + +int +foo () +{ + int r = 0; + [&r] () { +#pragma omp parallel for reduction(+ : r) + for (int i = 0; i < 1024; ++i) + r += i; + } (); + return r; +} + +int +bar () +{ + int l = 0; + [&l] () { +#pragma omp parallel for lastprivate (l) + for (int i = 0; i < 1024; ++i) + l = i; + } (); + return l; +} + +void +baz () +{ + int f = 18; + [&f] () { +#pragma omp parallel for firstprivate (f) + for (int i = 0; i < 1024; ++i) + { + sink (f); + f += 3; + sink (f); + if (f != 23) + abort (); + sink (f); + f -= 7; + sink (f); + } + } (); + if (f != 18) + abort (); +} + +int +qux () +{ + int r = 0; + [&] () { +#pragma omp parallel for reduction(+ : r) + for (int i = 0; i < 1024; ++i) + r += i; + } (); + return r; +} + +int +corge () +{ + int l = 0; + [&] () { +#pragma omp parallel for lastprivate (l) + for (int i = 0; i < 1024; ++i) + l = i; + } (); + return l; +} + +void +garply () +{ + int f = 18; + [&] () { +#pragma omp parallel for firstprivate (f) + for (int i = 0; i < 1024; ++i) + { + sink (f); + f += 3; + sink (f); + if (f != 23) + abort (); + sink (f); + f -= 7; + sink (f); + } + } (); + if (f != 18) + abort (); +} + +int +main () +{ + if (foo () != 1024 * 1023 / 2) + abort (); + if (bar () != 1023) + abort (); + baz (); + if (qux () != 1024 * 1023 / 2) + abort (); + if (corge () != 1023) + abort (); + garply (); +}