Re: PR82943 - Suggested patch to fix
Hi All, I have gone through the PDT problem reports and made sure that they block PR82173. To my utter astonishment (i) There might be only one duplicate; and (ii) Only 82649, 84119, 90218, 95541, 99079, 102901 & 105380 (out of 50 PRs) depend on the representation. Regards Paul
[PATCH 1/7] Fix up merge/formatting errors
This patch fixes a couple of minor merge/formatting errors. 2023-06-30 Julian Brown gcc/fortran/ * parse.cc (decode_omp_directive): Add missing break. gcc/ * gimplify.cc (gimplify_adjust_omp_clauses): Fix indentation. --- gcc/fortran/parse.cc | 1 + gcc/gimplify.cc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 73f15608260..2467adf5836 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -902,6 +902,7 @@ decode_omp_directive (void) break; case 't': matchs ("tile sizes", gfc_match_omp_tile, ST_OMP_TILE); + break; case 'u': matchs ("unroll", gfc_match_omp_unroll, ST_OMP_UNROLL); break; diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 1e90d2ed031..707a0c046de 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -13996,8 +13996,8 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p, fb_lvalue) == GS_ERROR) remove = true; gimplify_omp_ctxp = ctx; - break; -} + break; + } if ((code == OMP_TARGET || code == OMP_TARGET_DATA -- 2.25.1
[PATCH 0/7] [og13] OpenMP: lvalue parsing and "declare mapper" support
This patch series provides generalised lvalue ("locator list item") parsing for OpenMP "map", "to" and "from" clauses for C and C++, and "declare mapper" support for C, C++ and Fortran. It is based on the latter part of the patch series sent upstream previously: https://gcc.gnu.org/pipermail/gcc-patches/2022-December/609031.html (parts 7, 8, 9, 10 and 11), with adjustments necessary due to other patches already on og13 and also a few follow-up fixes. Tested with offloading to AMD GCN. I will apply (to og13) shortly. Julian Brown (7): Fix up merge/formatting errors OpenMP: OpenMP 5.2 semantics for pointers with unmapped target OpenMP: lvalue parsing for map/to/from clauses (C++) OpenMP: C++ "declare mapper" support OpenMP: lvalue parsing for map clauses (C) OpenMP: Support OpenMP 5.0 "declare mapper" directives for C OpenMP: Fortran "!$omp declare mapper" support gcc/c-family/c-common.h |7 +- gcc/c-family/c-omp.cc | 323 +- gcc/c-family/c-pretty-print.cc| 12 + gcc/c/c-decl.cc | 169 + gcc/c/c-objc-common.h | 12 + gcc/c/c-parser.cc | 463 ++- gcc/c/c-tree.h| 10 + gcc/c/c-typeck.cc | 128 +- gcc/cp/constexpr.cc | 10 + gcc/cp/cp-gimplify.cc |6 + gcc/cp/cp-objcp-common.h |9 + gcc/cp/cp-tree.h | 19 +- gcc/cp/decl.cc| 27 +- gcc/cp/decl2.cc | 54 +- gcc/cp/error.cc | 34 + gcc/cp/parser.cc | 497 ++- gcc/cp/parser.h |3 + gcc/cp/pt.cc | 78 +- gcc/cp/semantics.cc | 261 +- gcc/cp/typeck.cc | 50 + gcc/fortran/dump-parse-tree.cc|4 + gcc/fortran/f95-lang.cc |7 + gcc/fortran/gfortran.h| 56 +- gcc/fortran/match.cc |9 +- gcc/fortran/match.h |1 + gcc/fortran/module.cc | 251 +- gcc/fortran/openmp.cc | 299 +- gcc/fortran/parse.cc | 18 +- gcc/fortran/resolve.cc|2 + gcc/fortran/st.cc |2 +- gcc/fortran/symbol.cc | 16 + gcc/fortran/trans-decl.cc | 33 +- gcc/fortran/trans-openmp.cc | 785 +++- gcc/fortran/trans-stmt.h |1 + gcc/fortran/trans.h |3 + gcc/gimplify.cc | 583 ++- gcc/langhooks-def.h | 13 + gcc/langhooks.cc | 35 + gcc/langhooks.h | 16 + gcc/omp-general.h | 86 + .../c-c++-common/gomp/declare-mapper-12.c | 22 + .../c-c++-common/gomp/declare-mapper-3.c | 30 + .../c-c++-common/gomp/declare-mapper-4.c | 78 + .../c-c++-common/gomp/declare-mapper-5.c | 26 + .../c-c++-common/gomp/declare-mapper-6.c | 23 + .../c-c++-common/gomp/declare-mapper-7.c | 29 + .../c-c++-common/gomp/declare-mapper-8.c | 43 + .../c-c++-common/gomp/declare-mapper-9.c | 34 + gcc/testsuite/c-c++-common/gomp/map-6.c | 14 +- gcc/testsuite/g++.dg/gomp/array-section-1.C | 38 + gcc/testsuite/g++.dg/gomp/array-section-2.C | 63 + .../g++.dg/gomp/bad-array-section-1.C | 35 + .../g++.dg/gomp/bad-array-section-10.C| 35 + .../g++.dg/gomp/bad-array-section-11.C| 36 + .../g++.dg/gomp/bad-array-section-2.C | 33 + .../g++.dg/gomp/bad-array-section-3.C | 28 + .../g++.dg/gomp/bad-array-section-4.C | 50 + .../g++.dg/gomp/bad-array-section-5.C | 50 + .../g++.dg/gomp/bad-array-section-6.C | 24 + .../g++.dg/gomp/bad-array-section-7.C | 36 + .../g++.dg/gomp/bad-array-section-8.C | 53 + .../g++.dg/gomp/bad-array-section-9.C | 39 + gcc/testsuite/g++.dg/gomp/declare-mapper-1.C | 58 + gcc/testsuite/g++.dg/gomp/declare-mapper-2.C | 30 + .../gomp/has_device_addr-non-lvalue-1.C | 36 + gcc/testsuite/g++.dg/gomp/ind-base-3.C| 37 + gcc/testsuite/g++.dg/gomp/map-assignment-1.C | 12 + gcc/testsuite/g++.dg/gomp/map-inc-1.C | 10 + gcc/testsuite/g++.dg/gomp/map-lvalue-ref-1.C | 19 + gcc/testsuite/g++.dg/gomp/map-ptrmem-1.C | 37 + gcc/testsuite/g++.dg/gomp/map-ptrmem-2.C | 40 + .../g++.dg/gomp/map-static-cast-lvalue-1.C| 17 + gcc/testsuite/g++.dg/gomp/map-ternary-1.C
[PATCH 2/7] OpenMP: OpenMP 5.2 semantics for pointers with unmapped target
This patch fixes two more cases where an unmapped target pointer results in a null pointer on the target instead of a copy of the host pointer. The latter behaviour is required by OpenMP 5.2, which is a change from earlier versions of the standard. This change has already been made in one place by Tobias's patch here: https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622018.html But this patch makes a similar adjustment in other places (i.e. for GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION and GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION). These changes also revealed a problem with DECL_VALUE_EXPR handling in gimplify.cc, which this patch also fixes. 2023-06-30 Julian Brown gcc/ * gimplify.cc (gimplify_scan_omp_clauses): Add note about DECL_VALUE_EXPR handling for struct mapping nodes. (gimplify_adjust_omp_clauses): Perform DECL_VALUE_EXPR substitution before DECL_P check. libgomp/ * target.c (gomp_map_pointer): Modify zero-length array section pointer handling. (gomp_attach_pointer): Likewise. * testsuite/libgomp.c++/target-lambda-1.C: Update for OpenMP 5.2 semantics. * testsuite/libgomp.c++/target-this-3.C: Likewise. * testsuite/libgomp.c++/target-this-4.C: Likewise. --- gcc/gimplify.cc | 20 ++- libgomp/target.c | 7 +++ .../testsuite/libgomp.c++/target-lambda-1.C | 5 - libgomp/testsuite/libgomp.c++/target-this-3.C | 11 ++ libgomp/testsuite/libgomp.c++/target-this-4.C | 11 ++ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 707a0c046de..0e856b903ec 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -12090,7 +12090,13 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, /* Adding the decl for a struct access: we haven't created GOMP_MAP_STRUCT nodes yet, so this statement needs to predict -whether they will be created in gimplify_adjust_omp_clauses. */ +whether they will be created in gimplify_adjust_omp_clauses. +NOTE: Technically we should probably look through DECL_VALUE_EXPR +here because something that looks like a DECL_P may actually be a +struct access, e.g. variables in a lambda closure +(__closure->__foo) or class members (this->foo). Currently in both +those cases we map the whole of the containing object (directly in +the C++ FE) though, so struct nodes are not created. */ if (c == grp_end && addr_tokens[0]->type == STRUCTURE_BASE && addr_tokens[0]->u.structure_base_kind == BASE_DECL @@ -13895,6 +13901,18 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p, remove = true; break; } + /* If we have a DECL_VALUE_EXPR (e.g. this is a class member and/or +a variable captured in a lambda closure), look through that now +before the DECL_P check below. (A code other than COMPONENT_REF, +i.e. INDIRECT_REF, will be a VLA/variable-length array +section. A global var may be a variable in a common block. We +don't want to do this here for either of those.) */ + if ((ctx->region_type & ORT_ACC) == 0 + && DECL_P (decl) + && !is_global_var (decl) + && DECL_HAS_VALUE_EXPR_P (decl) + && TREE_CODE (DECL_VALUE_EXPR (decl)) == COMPONENT_REF) + decl = OMP_CLAUSE_DECL (c) = DECL_VALUE_EXPR (decl); if (TREE_CODE (decl) == TARGET_EXPR) { if (gimplify_expr (&OMP_CLAUSE_DECL (c), pre_p, NULL, diff --git a/libgomp/target.c b/libgomp/target.c index fbc84c68952..4447675cd16 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -855,7 +855,7 @@ gomp_map_pointer (struct target_mem_desc *tgt, struct goacc_asyncqueue *aq, if (n == NULL) { if (allow_zero_length_array_sections) - cur_node.tgt_offset = 0; + cur_node.tgt_offset = cur_node.host_start; else if (devicep->is_usm_ptr_func && devicep->is_usm_ptr_func ((void*)cur_node.host_start)) cur_node.tgt_offset = cur_node.host_start; @@ -1023,9 +1023,8 @@ gomp_attach_pointer (struct gomp_device_descr *devicep, { if (allow_zero_length_array_sections) /* When allowing attachment to zero-length array sections, we - allow attaching to NULL pointers when the target region is not - mapped. */ - data = 0; + copy the host pointer when the target region is not mapped. */ + data = target; else { gomp_mutex_unlock (&devicep->lock); diff --git a/libgomp/testsuite/libgomp.c++/target-lambda-1.C b/libgomp/testsuite/libgomp.c++/target-lambda-1.
[PATCH 4/7] OpenMP: C++ "declare mapper" support
This patch adds support for OpenMP 5.0 "declare mapper" functionality for C++. I've merged it to og13 based on the last version posted upstream, with some minor changes due to the newly-added 'present' map modifier support. There's also a fix to splay-tree traversal in gimplify.cc:omp_instantiate_implicit_mappers, and this patch omits the rearrangement of gimplify.cc:gimplify_{scan,adjust}_omp_clauses that I separated out into its own patch and applied (to og13) already. 2023-06-30 Julian Brown gcc/c-family/ * c-common.h (omp_mapper_list): Add forward declaration. (c_omp_find_nested_mappers, c_omp_instantiate_mappers): Add prototypes. * c-omp.cc (c_omp_find_nested_mappers): New function. (remap_mapper_decl_info): New struct. (remap_mapper_decl_1, omp_instantiate_mapper, c_omp_instantiate_mappers): New functions. gcc/cp/ * constexpr.cc (reduced_constant_expression_p): Add OMP_DECLARE_MAPPER case. (cxx_eval_constant_expression, potential_constant_expression_1): Likewise. * cp-gimplify.cc (cxx_omp_finish_mapper_clauses): New function. * cp-objcp-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES, LANG_HOOKS_OMP_MAPPER_LOOKUP, LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE, LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks. * cp-tree.h (lang_decl_base): Add omp_declare_mapper_p field. Recount spare bits comment. (DECL_OMP_DECLARE_MAPPER_P): New macro. (omp_mapper_id, cp_check_omp_declare_mapper, omp_instantiate_mappers, cxx_omp_finish_mapper_clauses, cxx_omp_mapper_lookup, cxx_omp_extract_mapper_directive, cxx_omp_map_array_section: Add prototypes. * decl.cc (check_initializer): Add OpenMP declare mapper support. (cp_finish_decl): Set DECL_INITIAL for OpenMP declare mapper var decls as appropriate. * decl2.cc (mark_used): Instantiate OpenMP "declare mapper" magic var decls. * error.cc (dump_omp_declare_mapper): New function. (dump_simple_decl): Use above. * parser.cc (cp_parser_omp_clause_map): Add KIND parameter. Support "mapper" modifier. (cp_parser_omp_all_clauses): Add KIND argument to cp_parser_omp_clause_map call. (cp_parser_omp_target): Call omp_instantiate_mappers before finish_omp_clauses. (cp_parser_omp_declare_mapper): New function. (cp_parser_omp_declare): Add "declare mapper" support. * pt.cc (tsubst_decl): Adjust name of "declare mapper" magic var decls once we know their type. (tsubst_omp_clauses): Call omp_instantiate_mappers before finish_omp_clauses, for target regions. (tsubst_expr): Support OMP_DECLARE_MAPPER nodes. (instantiate_decl): Instantiate initialiser (i.e definition) for OpenMP declare mappers. * semantics.cc (gimplify.h): Include. (omp_mapper_id, omp_mapper_lookup, omp_extract_mapper_directive, cxx_omp_map_array_section, cp_check_omp_declare_mapper): New functions. (finish_omp_clauses): Delete GOMP_MAP_PUSH_MAPPER_NAME and GOMP_MAP_POP_MAPPER_NAME artificial clauses. (omp_target_walk_data): Add MAPPERS field. (finish_omp_target_clauses_r): Scan for uses of struct/union/class type variables. (finish_omp_target_clauses): Create artificial mapper binding clauses for used structs/unions/classes in offload region. gcc/fortran/ * parse.cc (tree.h, fold-const.h, tree-hash-traits.h): Add includes (for additions to omp-general.h). gcc/ * gimplify.cc (gimplify_omp_ctx): Add IMPLICIT_MAPPERS field. (new_omp_context): Initialise IMPLICIT_MAPPERS hash map. (delete_omp_context): Delete IMPLICIT_MAPPERS hash map. (instantiate_mapper_info): New structs. (remap_mapper_decl_1, omp_mapper_copy_decl, omp_instantiate_mapper, omp_instantiate_implicit_mappers): New functions. (gimplify_scan_omp_clauses): Handle MAPPER_BINDING clauses. (gimplify_adjust_omp_clauses): Instantiate implicit declared mappers. (gimplify_omp_declare_mapper): New function. (gimplify_expr): Call above function. * langhooks-def.h (lhd_omp_finish_mapper_clauses, lhd_omp_mapper_lookup, lhd_omp_extract_mapper_directive, lhd_omp_map_array_section): Add prototypes. (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES, LANG_HOOKS_OMP_MAPPER_LOOKUP, LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE, LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define macros. (LANG_HOOK_DECLS): Add above macros. * langhooks.cc (lhd_omp_finish_mapper_clauses, lhd_omp_mapper_lookup, lhd_omp_extract_mapper_directive, lhd_omp_map_array_section): New dummy functions. * langhooks.h (lang_hooks_for_decls): Add OMP_FINISH_MAPPER_CLAUSES, OMP_MAPPER_LOOKUP, OMP_EXTRACT_MAPPER_DIRECTIVE, OMP_
[PATCH 6/7] OpenMP: Support OpenMP 5.0 "declare mapper" directives for C
This patch adds support for "declare mapper" directives (and the "mapper" modifier on "map" clauses) for C. 2023-06-30 Julian Brown gcc/c/ * c-decl.cc (c_omp_mapper_id, c_omp_mapper_decl, c_omp_mapper_lookup, c_omp_extract_mapper_directive, c_omp_map_array_section, c_omp_scan_mapper_bindings_r, c_omp_scan_mapper_bindings): New functions. * c-objc-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES, LANG_HOOKS_OMP_MAPPER_LOOKUP, LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE, LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks for C. * c-parser.cc (c_parser_omp_clause_map): Add KIND parameter. Handle mapper modifier. (c_parser_omp_all_clauses): Update call to c_parser_omp_clause_map with new kind argument. (c_parser_omp_target): Instantiate explicit mappers and record bindings for implicit mappers. (c_parser_omp_declare_mapper): Parse "declare mapper" directives. (c_parser_omp_declare): Support "declare mapper". * c-tree.h (c_omp_finish_mapper_clauses, c_omp_mapper_lookup, c_omp_extract_mapper_directive, c_omp_map_array_section, c_omp_mapper_id, c_omp_mapper_decl, c_omp_scan_mapper_bindings, c_omp_instantiate_mappers): Add prototypes. * c-typeck.cc (c_finish_omp_clauses): Handle GOMP_MAP_PUSH_MAPPER_NAME and GOMP_MAP_POP_MAPPER_NAME. (c_omp_finish_mapper_clauses): New function (langhook). gcc/testsuite/ * c-c++-common/gomp/declare-mapper-4.c: Enable for C. * c-c++-common/gomp/declare-mapper-5.c: Likewise. * c-c++-common/gomp/declare-mapper-6.c: Likewise. * c-c++-common/gomp/declare-mapper-7.c: Likewise. * c-c++-common/gomp/declare-mapper-8.c: Likewise. * c-c++-common/gomp/declare-mapper-9.c: Likewise. * c-c++-common/gomp/declare-mapper-12.c: Enable for C. * gcc.dg/gomp/declare-mapper-10.c: New test. * gcc.dg/gomp/declare-mapper-11.c: New test. libgomp/ * testsuite/libgomp.c-c++-common/declare-mapper-9.c: Enable for C. * testsuite/libgomp.c-c++-common/declare-mapper-10.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-11.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-12.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-13.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-14.c: Likewise. --- gcc/c/c-decl.cc | 169 +++ gcc/c/c-objc-common.h | 12 + gcc/c/c-parser.cc | 279 -- gcc/c/c-tree.h| 8 + gcc/c/c-typeck.cc | 15 + .../c-c++-common/gomp/declare-mapper-12.c | 2 +- .../c-c++-common/gomp/declare-mapper-4.c | 2 +- .../c-c++-common/gomp/declare-mapper-5.c | 2 +- .../c-c++-common/gomp/declare-mapper-6.c | 2 +- .../c-c++-common/gomp/declare-mapper-7.c | 2 +- .../c-c++-common/gomp/declare-mapper-8.c | 2 +- .../c-c++-common/gomp/declare-mapper-9.c | 2 +- gcc/testsuite/gcc.dg/gomp/declare-mapper-10.c | 61 gcc/testsuite/gcc.dg/gomp/declare-mapper-11.c | 33 +++ .../libgomp.c-c++-common/declare-mapper-10.c | 2 +- .../libgomp.c-c++-common/declare-mapper-11.c | 2 +- .../libgomp.c-c++-common/declare-mapper-12.c | 2 +- .../libgomp.c-c++-common/declare-mapper-13.c | 2 +- .../libgomp.c-c++-common/declare-mapper-14.c | 2 +- .../libgomp.c-c++-common/declare-mapper-9.c | 2 +- 20 files changed, 573 insertions(+), 30 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/declare-mapper-10.c create mode 100644 gcc/testsuite/gcc.dg/gomp/declare-mapper-11.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index b82bf5b4a48..ca9c72f99e5 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -13136,6 +13136,175 @@ c_check_omp_declare_reduction_r (tree *tp, int *, void *data) return NULL_TREE; } +/* Return identifier to look up for omp declare reduction. */ + +tree +c_omp_mapper_id (tree mapper_id) +{ + const char *p = NULL; + + const char prefix[] = "omp declare mapper "; + + if (mapper_id == NULL_TREE) +p = ""; + else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE) +p = IDENTIFIER_POINTER (mapper_id); + else +return error_mark_node; + + size_t lenp = sizeof (prefix); + size_t len = strlen (p); + char *name = XALLOCAVEC (char, lenp + len); + memcpy (name, prefix, lenp - 1); + memcpy (name + lenp - 1, p, len + 1); + return get_identifier (name); +} + +/* Lookup MAPPER_ID in the current scope, or create an artificial + VAR_DECL, bind it into the current scope and return it. */ + +tree +c_omp_mapper_decl (tree mapper_id) +{ + struct c_binding *b = I_SYMBOL_BINDING (mapper_id); + if (b != NULL && B_IN_CURRENT_SCOPE (b)) +return b->decl; + + tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL, +
[PATCH 5/7] OpenMP: lvalue parsing for map clauses (C)
This patch adds support for parsing general lvalues ("locator list item types") for OpenMP "map", "to" and "from" clauses to the C front-end, similar to the previously-posted patch for C++. 2023-06-30 Julian Brown gcc/c/ * c-pretty-print.cc (c_pretty_printer::postfix_expression, c_pretty_printer::expression): Add OMP_ARRAY_SECTION support. * c-parser.cc (c_parser_braced_init, c_parser_conditional_expression): Don't allow OpenMP array section. (c_parser_postfix_expression): Don't allow array section in statement expression. (c_parser_postfix_expression_after_primary): Add support for OpenMP array section parsing. (c_parser_expr_list): Don't allow OpenMP array section here. (c_parser_omp_variable_list): Change ALLOW_DEREF parameter to MAP_LVALUE. Support parsing of general lvalues in "map", "to" and "from" clauses. (c_parser_omp_var_list_parens): Change ALLOW_DEREF parameter to MAP_LVALUE. Update call to c_parser_omp_variable_list. (c_parser_oacc_data_clause): Update calls to c_parser_omp_var_list_parens. (c_parser_omp_clause_reduction): Use OMP_ARRAY_SECTION tree node instead of TREE_LIST for array sections. (c_parser_omp_target): Allow GOMP_MAP_ATTACH. * c-tree.h (c_omp_array_section_p): Add extern declaration. (build_omp_array_section): Add prototype. * c-typeck.c (c_omp_array_section_p): Add flag. (mark_exp_read): Support OMP_ARRAY_SECTION. (build_omp_array_section): Add function. (build_external_ref): Tweak error path for OpenMP array sections. (handle_omp_array_sections_1): Use OMP_ARRAY_SECTION tree code instead of TREE_LIST. Handle more kinds of expressions. (c_oacc_check_attachments): Use OMP_ARRAY_SECTION instead of TREE_LIST for array sections. (c_finish_omp_clauses): Use OMP_ARRAY_SECTION instead of TREE_LIST. Check for supported expression types. gcc/testsuite/ * gcc.dg/gomp/bad-array-section-c-1.c: New test. * gcc.dg/gomp/bad-array-section-c-2.c: New test. * gcc.dg/gomp/bad-array-section-c-3.c: New test. * gcc.dg/gomp/bad-array-section-c-4.c: New test. * gcc.dg/gomp/bad-array-section-c-5.c: New test. * gcc.dg/gomp/bad-array-section-c-6.c: New test. * gcc.dg/gomp/bad-array-section-c-7.c: New test. * gcc.dg/gomp/bad-array-section-c-8.c: New test. libgomp/ * testsuite/libgomp.c-c++-common/ind-base-4.c: New test. * testsuite/libgomp.c-c++-common/unary-ptr-1.c: New test. --- gcc/c-family/c-pretty-print.cc| 12 ++ gcc/c/c-parser.cc | 184 +++--- gcc/c/c-tree.h| 2 + gcc/c/c-typeck.cc | 113 --- .../gcc.dg/gomp/bad-array-section-c-1.c | 16 ++ .../gcc.dg/gomp/bad-array-section-c-2.c | 13 ++ .../gcc.dg/gomp/bad-array-section-c-3.c | 24 +++ .../gcc.dg/gomp/bad-array-section-c-4.c | 26 +++ .../gcc.dg/gomp/bad-array-section-c-5.c | 15 ++ .../gcc.dg/gomp/bad-array-section-c-6.c | 16 ++ .../gcc.dg/gomp/bad-array-section-c-7.c | 26 +++ .../gcc.dg/gomp/bad-array-section-c-8.c | 21 ++ .../libgomp.c-c++-common/ind-base-4.c | 50 + .../libgomp.c-c++-common/unary-ptr-1.c| 16 ++ 14 files changed, 487 insertions(+), 47 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-1.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-2.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-3.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-4.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-5.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-6.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-7.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-section-c-8.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/ind-base-4.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/unary-ptr-1.c diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index 7536a7c471f..225ac7ef285 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -1615,6 +1615,17 @@ c_pretty_printer::postfix_expression (tree e) pp_c_right_bracket (this); break; +case OMP_ARRAY_SECTION: + postfix_expression (TREE_OPERAND (e, 0)); + pp_c_left_bracket (this); + if (TREE_OPERAND (e, 1)) + expression (TREE_OPERAND (e, 1)); + pp_colon (this); + if (TREE_OPERAND (e, 2)) + expression (TREE_OPERAND (e, 2)); + pp_c_right_bracket (this); + break; + case CALL_EXPR: { call_expr_arg_iterator iter; @@ -2664,6 +2675,7 @@ c_pretty_printer::expression (tree
[PATCH 7/7] OpenMP: Fortran "!$omp declare mapper" support
This patch implements "omp declare mapper" functionality for Fortran, following the equivalent support for C and C++. This version of the patch has been merged to og13 and contains various fixes for e.g.: * Mappers with deferred-length strings * Array descriptors not being appropriately transferred to the offload target (see "OMP_MAP_POINTER_ONLY" and gimplify.cc:omp_maybe_get_descriptor_from_ptr). 2023-06-30 Julian Brown gcc/fortran/ * dump-parse-tree.cc (show_attr): Show omp_udm_artificial_var flag. (show_omp_namelist): Support OMP_MAP_POINTER_ONLY and OMP_MAP_UNSET. * f95-lang.cc (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES, LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE, LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define language hooks. * gfortran.h (gfc_statement): Add ST_OMP_DECLARE_MAPPER. (symbol_attribute): Add omp_udm_artificial_var attribute. (gfc_omp_map_op): Add OMP_MAP_POINTER_ONLY and OMP_MAP_UNSET. (gfc_omp_namelist): Add udm pointer to u2 union. (gfc_omp_udm): New struct. (gfc_omp_namelist_udm): New struct. (gfc_symtree): Add omp_udm pointer. (gfc_namespace): Add omp_udm_root symtree. Add omp_udm_ns flag. (gfc_free_omp_namelist): Update prototype. (gfc_free_omp_udm, gfc_omp_udm_find, gfc_find_omp_udm, gfc_resolve_omp_udms): Add prototypes. * match.cc (gfc_free_omp_namelist): Change FREE_NS and FREE_ALIGN parameters to LIST number, to handle freeing user-defined mapper namelists safely. * match.h (gfc_match_omp_declare_mapper): Add prototype. * module.cc (ab_attribute): Add AB_OMP_DECLARE_MAPPER_VAR. (attr_bits): Add OMP_DECLARE_MAPPER_VAR. (mio_symbol_attribute): Read/write AB_OMP_DECLARE_MAPPER_VAR attribute. Set referenced attr on read. (omp_map_clause_ops, omp_map_cardinality): New arrays. (load_omp_udms, check_omp_declare_mappers): New functions. (read_module): Load and check OMP declare mappers. (write_omp_udm, write_omp_udms): New functions. (write_module): Write OMP declare mappers. * openmp.cc (gfc_free_omp_clauses, gfc_match_omp_variable_list, gfc_match_omp_to_link, gfc_match_omp_depend_sink, gfc_match_omp_clause_reduction): Update calls to gfc_free_omp_namelist. (gfc_free_omp_udm, gfc_find_omp_udm, gfc_omp_udm_find, gfc_match_omp_declare_mapper): New functions. (gfc_match_omp_clauses): Add DEFAULT_MAP_OP parameter. Update calls to gfc_free_omp_namelist. Add declare mapper support. (resolve_omp_clauses): Add declare mapper support. Update calls to gfc_free_omp_namelist. (gfc_resolve_omp_udm, gfc_resolve_omp_udms): New functions. * parse.cc (decode_omp_directive): Add declare mapper support. (case_omp_decl): Add ST_OMP_DECLARE_MAPPER case. (gfc_ascii_statement): Add ST_OMP_DECLARE_MAPPER case. * resolve.cc (resolve_types): Call gfc_resolve_omp_udms. * st.cc (gfc_free_statement): Update call to gfc_free_omp_namelist. * symbol.cc (free_omp_udm_tree): New function. (gfc_free_namespace): Call above. * trans-decl.cc (omp_declare_mapper_ns): New global. (gfc_finish_var_decl, gfc_generate_function_code): Support declare mappers. (gfc_trans_deferred_vars): Ignore artificial declare-mapper vars. * trans-openmp.cc (tree-iterator.h): Include. (toc_directive): New enum. (gfc_trans_omp_array_section): Change OP and OPENMP parameters to toc_directive CD ('clause directive'). (gfc_omp_finish_mapper_clauses, gfc_omp_extract_mapper_directive, gfc_omp_map_array_section): New functions. (omp_clause_directive): New enum. (gfc_trans_omp_clauses): Remove DECLARE_SIMD and OPENACC parameters. Replace with toc_directive CD, defaulting to TOC_OPENMP. Add declare mapper support and OMP_MAP_POINTER_ONLY support. (gfc_trans_omp_construct, gfc_trans_oacc_executable_directive, gfc_trans_oacc_combined_directive): Update calls to gfc_trans_omp_clauses. (gfc_subst_replace, gfc_subst_prepend_ref): New variables. (gfc_subst_in_expr_1, gfc_subst_in_expr, gfc_subst_mapper_var, gfc_trans_omp_instantiate_mapper, gfc_trans_omp_instantiate_mappers, gfc_record_mapper_bindings_code_fn, gfc_record_mapper_bindings_expr_fn, gfc_find_nested_mappers, gfc_record_mapper_bindings): New functions. (gfc_typespec * hash traits): New template. (omp_declare_mapper_ns): Extern declaration. (gfc_trans_omp_target): Call gfc_trans_omp_instantiate_mappers and gfc_record_mapper_bindings. Update calls to gfc_trans_omp_clauses. (gfc_trans_omp_declare_simd, gfc_trans_omp_declare_variant): Update calls to gfc_trans_omp_clauses. (gfc_trans_omp_mapper_name, gfc