From patchwork Tue May 11 21:54:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1477324 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4FfsD229bFz9sWB for ; Wed, 12 May 2021 07:55:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59A5B3838037; Tue, 11 May 2021 21:55:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 5FE323886C46 for ; Tue, 11 May 2021 21:55:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5FE323886C46 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: 5H+QCFmx/Lh8FsIpNV48+EQgg2ItMFiuKGIcZYscS+BErcUQrsWhFJlyf3zkpTZohnqKNFhaob Be96GzEsFMziyv6xo2KCfSIxL4hkvsnTa8oN1DYpy3Uksv05slhGduWLr3yub7HbeR5/Q76e5I zsvH2iPDSGwcYczbvH0+LtcKT4HlBaGIsgD3rfi18yJojPoNU/qeEAZqpyL2CdBuNsr3YrgflB H/6l0R/0SmaRGvw2DFvip40Nqby38xAiyZcmNwGbQZMQVDqd900UVNKKtNG/gDN0A7kqNyHEYp r3g= X-IronPort-AV: E=Sophos;i="5.82,291,1613462400"; d="diff'?scan'208";a="61241733" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 11 May 2021 13:55:04 -0800 IronPort-SDR: /RMk7fa3G8h2M5xYxbPWZnniOZHJ5KU+4sTVF8Hom9B/FdoZROZ0/rtrmEARoWy3ChWhQjgRNd OmHCFBDwHO0iaupsxijiJ3n44dWBWJCHVGjKhvjwOxZxU/Em2q7ypQh1v5WxsZghuYfkx65pia 504PEb+eH+Jsp+z5P6sDBW2IlzCzO1eUtlYbdMTHNmlzKeOZ1fhz5NleGKclzjjXZBfDsC6uw+ 104Ib4UJDlraHAtgQLP1HvrjCOYV5KDOabql5fx8700ofYOldXcxRaq5hHXQisoekdcCFcJwnH Z6Q= To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP: detach - fix firstprivate handling Message-ID: <9e2b02be-abf4-7bf6-e12d-11fcbeb201fc@codesourcery.com> Date: Tue, 11 May 2021 23:54:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The sfield / firstprivate lookup used the wrong var decl for the lookup – hence it failed. I used an extra long diff to make it easier to follow why 'c' and not 'detach_clause' has the proper clause for the decl to be used as key. Testsuite run ongoing. OK for mainline, when it passes? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf OpenMP: detach - fix firstprivate handling gcc/ChangeLog: * omp-low.c (finish_taskreg_scan): Use the proper detach decl. libgomp/ChangeLog: * testsuite/libgomp.fortran/detach-1.f90: New test. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index c0ce1a4990e..cadca7e201f 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -2436,55 +2436,55 @@ finish_taskreg_scan (omp_context *ctx) /* Look for a firstprivate clause with the detach event handle. */ for (c = gimple_omp_taskreg_clauses (ctx->stmt); c; c = OMP_CLAUSE_CHAIN (c)) { if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE) continue; if (maybe_lookup_decl_in_outer_ctx (OMP_CLAUSE_DECL (c), ctx) == OMP_CLAUSE_DECL (detach_clause)) break; } gcc_assert (c); field = lookup_field (OMP_CLAUSE_DECL (c), ctx); /* Move field corresponding to the detach clause first. This is filled by GOMP_task and needs to be in a specific position. */ p = &TYPE_FIELDS (ctx->record_type); while (*p) if (*p == field) *p = DECL_CHAIN (*p); else p = &DECL_CHAIN (*p); DECL_CHAIN (field) = TYPE_FIELDS (ctx->record_type); TYPE_FIELDS (ctx->record_type) = field; if (ctx->srecord_type) { - field = lookup_sfield (OMP_CLAUSE_DECL (detach_clause), ctx); + field = lookup_sfield (OMP_CLAUSE_DECL (c), ctx); p = &TYPE_FIELDS (ctx->srecord_type); while (*p) if (*p == field) *p = DECL_CHAIN (*p); else p = &DECL_CHAIN (*p); DECL_CHAIN (field) = TYPE_FIELDS (ctx->srecord_type); TYPE_FIELDS (ctx->srecord_type) = field; } } layout_type (ctx->record_type); fixup_child_record_type (ctx); if (ctx->srecord_type) layout_type (ctx->srecord_type); tree t = fold_convert_loc (loc, long_integer_type_node, TYPE_SIZE_UNIT (ctx->record_type)); if (TREE_CODE (t) != INTEGER_CST) { t = unshare_expr (t); walk_tree (&t, finish_taskreg_remap, ctx, NULL); } gimple_omp_task_set_arg_size (ctx->stmt, t); t = build_int_cst (long_integer_type_node, TYPE_ALIGN_UNIT (ctx->record_type)); gimple_omp_task_set_arg_align (ctx->stmt, t); } } diff --git a/libgomp/testsuite/libgomp.fortran/detach-1.f90 b/libgomp/testsuite/libgomp.fortran/detach-1.f90 new file mode 100644 index 00000000000..88546fe473b --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/detach-1.f90 @@ -0,0 +1,22 @@ +program test + use omp_lib + implicit none + integer(omp_event_handle_kind) :: oevent, ievent + integer :: i + integer, allocatable :: temp(:) + ALLOCATE(temp(5)) + + !$omp parallel num_threads(3) + !$omp single + DO i=1,5 + !$omp task firstprivate(i) firstprivate(temp) detach(oevent) + temp(:) = 0; + temp(1) = -1; + !print *,temp + call omp_fulfill_event(oevent) + !$omp end task + ENDDO + !$omp taskwait + !$omp end single + !$omp end parallel +end program