From patchwork Wed Apr 5 12:08:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 67304 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 1850B3854175 for ; Wed, 5 Apr 2023 12:10:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 0D2053856945 for ; Wed, 5 Apr 2023 12:10:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D2053856945 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="1684139" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 05 Apr 2023 04:10:38 -0800 IronPort-SDR: Q1LQ+M/PlcHtLNK9Ki9Qhk+LctCFCRLBV0FDNRqZ10veoyBdBbd6tMTdZ9z0rgpQDvdrhmPpcQ fDC+26jpAtH55w/0n6HTIUYUtjxwHAhw4gL5QiiY2+pDeYFWheztQ0sykCMnKZI8gtQyko6Vz6 qPgYX6bp8Mulc/A6MFHBsilgMO9i84O0F5hKEKRB1CnnEEIMKFjNfW2CtEGZhUWeC7SeQUJZmj V5y8+UfU+AYnStTdM7VZcgRnKVcDk8NM92HI8eGNtk/yvrPg8Ox9YP2JjMsad1W/QbklZZwWzv xc4= From: Julian Brown To: CC: Thomas Schwinge Subject: [PATCH] [og12] OpenMP: Fix checking ICE in "declare target" ctor/dtor support Date: Wed, 5 Apr 2023 12:08:33 +0000 Message-ID: <20230405120833.3598320-1-julian@codesourcery.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch fixes an ICE with checking enabled with the patch: abcb5dbac666513c798e574808f849f76a1c0799 There were two problems: first, OMP_CLAUSE_CHAIN was erroneously used as the chain pointer instead of TREE_CHAIN for a non-OMP clause list. Secondly, "copy_node" by itself is not sufficient to clone the initialization statement for use in the on-target constructor/destructor function. Instead we now use walk_tree with "copy_tree_body_r" and appropriate configuration parameters. Tested with offloading to AMD GCN. I will commit (to og12) shortly. Julian 2023-04-05 Julian Brown gcc/cp/ * decl2.cc (tree-inline.h): Include. (do_static_initialization_or_destruction): Change OMP_TARGET parameter to pass the host version of the SSDF function decl. Use copy_tree_body_r to clone init stmt. Update forward declaration. (c_parse_final_cleanups): Update calls to do_static_initialization_or_destruction. Use TREE_CHAIN instead of OMP_CLAUSE_CHAIN. --- gcc/cp/decl2.cc | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 9c007043963..4b4b211eb2a 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "asan.h" #include "optabs-query.h" #include "omp-general.h" +#include "tree-inline.h" /* Id for dumping the raw trees. */ int raw_dump_id; @@ -75,7 +76,7 @@ static void finish_objects (int, int, tree); static tree start_static_storage_duration_function (unsigned, bool); static void finish_static_storage_duration_function (tree); static priority_info get_priority_info (int); -static void do_static_initialization_or_destruction (tree, bool, bool); +static void do_static_initialization_or_destruction (tree, bool, tree); static void one_static_initialization_or_destruction (tree, tree, bool); static void generate_ctor_or_dtor_function (bool, int, location_t *, bool); static int generate_ctor_and_dtor_functions_for_priority (splay_tree_node, @@ -4314,9 +4315,11 @@ one_static_initialization_or_destruction (tree decl, tree init, bool initp) Whether initialization or destruction is performed is specified by INITP. */ static void -do_static_initialization_or_destruction (tree vars, bool initp, bool omp_target) +do_static_initialization_or_destruction (tree vars, bool initp, + tree host_ssdf_decl = NULL_TREE) { tree node, init_if_stmt, cond; + bool omp_target = host_ssdf_decl != NULL_TREE; /* Build the outer if-stmt to check for initialization or destruction. */ init_if_stmt = begin_if_stmt (); @@ -4386,7 +4389,25 @@ do_static_initialization_or_destruction (tree vars, bool initp, bool omp_target) /* We will emit 'init' twice, and it is modified in-place during gimplification. Make a copy here. */ if (omp_target) - init = copy_node (init); + { + /* We've already emitted INIT in the host version of the ctor/dtor + function. We need to deep-copy it (including new versions of + local variables introduced, etc.) for use in the target + ctor/dtor function. */ + copy_body_data id; + hash_map decl_map; + memset (&id, 0, sizeof (id)); + id.src_fn = host_ssdf_decl; + id.dst_fn = current_function_decl; + id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn); + id.decl_map = &decl_map; + id.copy_decl = copy_decl_no_change; + id.transform_call_graph_edges = CB_CGE_DUPLICATE; + id.transform_new_cfg = true; + id.transform_return_to_modify = false; + id.eh_lp_nr = 0; + walk_tree (&init, copy_tree_body_r, &id, NULL); + } /* Do one initialization or destruction. */ one_static_initialization_or_destruction (decl, init, initp); } @@ -5245,8 +5266,7 @@ c_parse_final_cleanups (void) /* First generate code to do all the initializations. */ if (vars) - do_static_initialization_or_destruction (vars, /*initp=*/true, - /*omp_target=*/false); + do_static_initialization_or_destruction (vars, /*initp=*/true); tree filtered_vars = NULL_TREE; @@ -5262,12 +5282,13 @@ c_parse_final_cleanups (void) if (!flag_use_cxa_atexit && vars) { vars = nreverse (vars); - do_static_initialization_or_destruction (vars, /*initp=*/false, - /*omp_target=*/false); + do_static_initialization_or_destruction (vars, /*initp=*/false); } else vars = NULL_TREE; + tree host_ssdf_decl = current_function_decl; + /* Finish up the static storage duration function for this round. */ input_location = locus_at_end_of_parsing; @@ -5286,9 +5307,9 @@ c_parse_final_cleanups (void) if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))) - fvarsp = &OMP_CLAUSE_CHAIN (*fvarsp); + fvarsp = &TREE_CHAIN (*fvarsp); else - *fvarsp = OMP_CLAUSE_CHAIN (*fvarsp); + *fvarsp = TREE_CHAIN (*fvarsp); } input_location = locus_at_end_of_parsing; @@ -5318,14 +5339,13 @@ c_parse_final_cleanups (void) do_static_initialization_or_destruction (filtered_vars, /*initp=*/true, - /*omp_target=*/true); + host_ssdf_decl); if (!flag_use_cxa_atexit && filtered_vars) { filtered_vars = nreverse (filtered_vars); do_static_initialization_or_destruction (filtered_vars, /*initp=*/false, - /*omp_target=*/ - false); + host_ssdf_decl); } else filtered_vars = NULL_TREE;