aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
AgeCommit message (Collapse)AuthorFilesLines
9 daysChangeLog.omp bumpSandra Loosemore1-0/+237
9 daysOpenMP: C/C++ adjust-args numeric rangeswaffl3x1-44/+860
Add support for OpenMP parameter-lists in an adjust_args clause, more specifically, numeric ranges and parameter indices. Many bugs are also fixed along the way. Most of the fixes rely on the changes to handling of clause arguments and can't reasonably be split out, while most of the changes that fix PR119602 came as a side effect of properly handling numeric ranges with dependent bounds so it makes sense to include it here. Variadic arguments with an incorrect type are not currently diagnosed, but handling for them is otherwise functional. It is unclear how references to pointers are supposed to be handled, so for now we sorry for that case. PR c++/119659 PR c++/118859 PR c++/119601 PR c++/119602 PR c++/119775 gcc/c/ChangeLog: * c-parser.cc (c_omp_numeric_ranges_always_overlap): New function. (c_parser_omp_parm_list): New function. (c_finish_omp_declare_variant): Use c_parser_omp_parm_list instead of c_parser_omp_variable_list. Refactor, change format of "omp declare variant variant args" attribute. gcc/cp/ChangeLog: PR c++/119659 PR c++/118859 PR c++/119601 PR c++/119602 PR c++/119775 * cp-tree.h (finish_omp_parm_list): New declaration. (finish_omp_adjust_args): New declaration. * decl.cc (omp_declare_variant_finalize_one): Refactor and change attribute unpacking, use finish_omp_parm_list and finish_omp_adjust_args, refactor append_args diagnostics, add nbase_parms to append_args attribute, remove special handling for member functions. * parser.cc (cp_parser_direct_declarator): Don't pass parms. (cp_parser_late_return_type_opt): Remove parms parameter. (cp_parser_omp_parm_list): New function. (cp_finish_omp_declare_variant): Remove parms parameter. Add NULL_TREE instead of nbase_args to append_args_tree. Refactor, use cp_parser_omp_parm_list not cp_parser_omp_var_list_no_open, handle "need_device_addr" and remove handling and diagnostics of parm list arguments that are done too early. Change format of unnamed variant attribute. (cp_parser_late_parsing_omp_declare_simd): Remove parms parameter. * pt.cc (tsubst_attribute): Copy "omp declare variant base" nodes, substitute parm list numeric range bounds. * semantics.cc (finish_omp_parm_list): New function. (finish_omp_adjust_args): New function. gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_declare_variant): Change format of "omp declare variant variant args" attribute. gcc/ChangeLog: * gimplify.cc (modify_call_for_omp_dispatch): Refactor and change attribute unpacking. For adjust_args variadic functions, expand numeric ranges with relative bounds. Refactor argument adjustment. libgomp/ChangeLog: * libgomp.texi: Set 'adjust args' variadic arguments support to Y. gcc/testsuite/ChangeLog: * c-c++-common/gomp/pr118579.c: Change error text. * g++.dg/gomp/adjust-args-1.C: Fix error text, add dg-* directives. * g++.dg/gomp/adjust-args-2.C: Add dg-* directives. * g++.dg/gomp/append-args-1.C: Add dg-* directives. * gcc.dg/gomp/adjust-args-1.c: Fix error text, add dg-* directives. * gcc.dg/gomp/append-args-1.c: Fix error text, add dg-* directives. * c-c++-common/gomp/adjust-args-7.c: New test. * c-c++-common/gomp/adjust-args-8.c: New test. * c-c++-common/gomp/adjust-args-9.c: New test. * c-c++-common/gomp/adjust-args-10.c: New test. * c-c++-common/gomp/adjust-args-11.c: New test. * c-c++-common/gomp/adjust-args-12.c: New test. * c-c++-common/gomp/adjust-args-13.c: New test. * c-c++-common/gomp/adjust-args-14.c: New test. * c-c++-common/gomp/adjust-args-15.c: New test. * g++.dg/gomp/adjust-args-5.C: New test. * g++.dg/gomp/adjust-args-6.C: New test. * g++.dg/gomp/adjust-args-7.C: New test. * g++.dg/gomp/adjust-args-8.C: New test. * g++.dg/gomp/adjust-args-9.C: New test. * g++.dg/gomp/adjust-args-10.C: New test. * g++.dg/gomp/adjust-args-11.C: New test. * g++.dg/gomp/adjust-args-12.C: New test. * g++.dg/gomp/adjust-args-13.C: New test. * g++.dg/gomp/adjust-args-14.C: New test. * g++.dg/gomp/adjust-args-15.C: New test. * g++.dg/gomp/adjust-args-16.C: New test. * g++.dg/gomp/append-args-9.C: New test. * g++.dg/gomp/append-args-10.C: New test. * g++.dg/gomp/append-args-11.C: New test. * g++.dg/gomp/append-args-omp-interop-t.h: New header. Signed-off-by: Waffl3x <waffl3x@baylibre.com>
9 daysopenmp: Add support for using custom mappers with iterators (C, C++)Kwok Cheung Yeung1-0/+4
gcc/c-family/ * c-omp.cc (omp_instantiate_mapper): Apply iterator to new clauses generated from mapper. gcc/c/ * c-parser.cc (c_parser_omp_clause_map): Apply iterator to push and pop mapper clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_map): Apply iterator to push and pop mapper clauses. * semantics.cc (cxx_omp_map_array_section): Allow array types for base type of array sections. libgomp/ * testsuite/libgomp.c-c++-common/mapper-iterators-1.c: New test. * testsuite/libgomp.c-c++-common/mapper-iterators-2.c: New test. * testsuite/libgomp.c-c++-common/mapper-iterators-3.c: New test. Co-authored-by: Andrew Stubbs <ams@baylibre.com>
9 daysopenmp: Add macros for iterator element accessKwok Cheung Yeung2-20/+20
gcc/c/ * c-parser.cc (c_parser_omp_iterators): Use macros for accessing iterator elements. (c_parser_omp_clause_affinity): Likewise. (c_parser_omp_clause_depend): Likewise. (c_parser_omp_clause_map): Likewise. (c_parser_omp_clause_from_to): Likewise. * c-typeck.cc (c_omp_finish_iterators): Likewise. gcc/cp/ * parser.cc (cp_parser_omp_iterators): Use macros for accessing iterator elements. (cp_parser_omp_clause_affinity): Likewise. (cp_parser_omp_clause_depend): Likewise. (cp_parser_omp_clause_from_to): Likewise. (cp_parser_omp_clause_map): Likewise. * semantics.cc (cp_omp_finish_iterators): Likewise. gcc/fortran/ * trans-openmp.cc (gfc_trans_omp_array_section): Use macros for accessing iterator elements. (handle_iterator): Likewise. (gfc_trans_omp_clauses): Likewise. gcc/ * gimplify.cc (gimplify_omp_affinity): Use macros for accessing iterator elements. (compute_omp_iterator_count): Likewise. (build_omp_iterator_loop): Likewise. (remove_unused_omp_iterator_vars): Likewise. (build_omp_iterators_loops): Likewise. (enter_omp_iterator_loop_context_1): Likewise. (extract_base_bit_offset): Likewise. * omp-low.cc (lower_omp_map_iterator_expr): Likewise. (lower_omp_map_iterator_size): Likewise. (allocate_omp_iterator_elems): Likewise. (free_omp_iterator_elems): Likewise. * tree-inline.cc (copy_tree_body_r): Likewise. * tree-pretty-print.cc (dump_omp_iterators): Likewise. * tree.h (OMP_ITERATORS_VAR, OMP_ITERATORS_BEGIN, OMP_ITERATORS_END, OMP_ITERATORS_STEP, OMP_ITERATORS_ORIG_STEP, OMP_ITERATORS_BLOCK, OMP_ITERATORS_LABEL, OMP_ITERATORS_INDEX, OMP_ITERATORS_ELEMS, OMP_ITERATORS_COUNT, OMP_ITERATORS_EXPANDED_P): New macros.
9 daysopenmp: Disable strided target updates when iterators are usedKwok Cheung Yeung1-3/+14
Non-contiguous target updates result in the new strided target updates code being used, resulting in new clauses such as GOMP_MAP_GRID_DIM, GOMP_MAP_GRID_STRIDE etc. These are not currently supported in conjunction with iterators, so this code-path is disabled when used together with iterators. The older target updates supports non-contiguous updates as long as a stride is not applied. gcc/c/ * c-typeck.cc (handle_omp_array_sections): Add extra argument. Set argument to true if array section has a stride that is not one. (c_finish_omp_clauses): Disable strided updates when iterators are used in the clause. Emit sorry if strided. gcc/cp/ * semantics.cc (handle_omp_array_sections): Add extra argument. Set argument to true if array section has a stride that is not one. (finish_omp_clauses): Disable strided updates when iterators are used in the clause. Emit sorry if strided. gcc/fortran/ * trans-openmp.cc (gfc_trans_omp_clauses): Disable strided updates when iterators are used in the clause.
9 daysopenmp: Add support for iterators in 'target update' clauses (C/C++)Kwok Cheung Yeung2-12/+48
This adds support for iterators in 'to' and 'from' clauses in the 'target update' OpenMP directive. gcc/c/ * c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier. * c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier. * semantics.cc (finish_omp_clauses): Finish iterators for to/from clauses. gcc/ * gimplify.cc (gimplify_scan_omp_clauses): Add argument for iterator loop sequence. Gimplify the clause decl and size into the iterator loop if iterators are used. (gimplify_omp_workshare): Add argument for iterator loops sequence in call to gimplify_scan_omp_clauses. (gimplify_omp_target_update): Call remove_unused_omp_iterator_vars and build_omp_iterators_loops. Add loop sequence as argument when calling gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building the Gimple statement. * tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators for to/from clauses with iterators. * tree.cc (omp_clause_num_ops): Add extra operand for OMP_CLAUSE_FROM and OMP_CLAUSE_TO. * tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and OMP_CLAUSE_FROM. (OMP_CLAUSE_ITERATORS): Likewise. gcc/testsuite/ * c-c++-common/gomp/target-update-iterators-1.c: New. * c-c++-common/gomp/target-update-iterators-2.c: New. * c-c++-common/gomp/target-update-iterators-3.c: New. libgomp/ * target.c (gomp_update): Call gomp_merge_iterator_maps. Free allocated variables. * testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New. * testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New. * testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.
9 daysopenmp: Add support for iterators in map clauses (C/C++)Kwok Cheung Yeung2-7/+69
This adds preliminary support for iterators in map clauses within OpenMP 'target' constructs (which includes constructs such as 'target enter data'). Iterators with non-constant loop bounds are not currently supported. gcc/c/ * c-parser.cc (c_parser_omp_clause_map): Parse 'iterator' modifier. * c-typeck.cc (c_finish_omp_clauses): Finish iterators. Apply iterators to generated clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_map): Parse 'iterator' modifier. * semantics.cc (finish_omp_clauses): Finish iterators. Apply iterators to generated clauses. gcc/ * gimple-pretty-print.cc (dump_gimple_omp_target): Print expanded iterator loops. * gimple.cc (gimple_build_omp_target): Add argument for iterator loops sequence. Initialize iterator loops field. * gimple.def (GIMPLE_OMP_TARGET): Set GSS symbol to GSS_OMP_TARGET. * gimple.h (gomp_target): Set GSS symbol to GSS_OMP_TARGET. Add extra field for iterator loops. (gimple_build_omp_target): Add argument for iterator loops sequence. (gimple_omp_target_iterator_loops): New. (gimple_omp_target_iterator_loops_ptr): New. (gimple_omp_target_set_iterator_loops): New. * gimplify.cc (find_var_decl): New. (copy_omp_iterator): New. (remap_omp_iterator_var_1): New. (remap_omp_iterator_var): New. (remove_unused_omp_iterator_vars): New. (struct iterator_loop_info_t): New type. (iterator_loop_info_map_t): New type. (build_omp_iterators_loops): New. (enter_omp_iterator_loop_context_1): New. (enter_omp_iterator_loop_context): New. (enter_omp_iterator_loop_context): New. (exit_omp_iterator_loop_context): New. (gimplify_adjust_omp_clauses): Add argument for iterator loop sequence. Gimplify the clause decl and size into the iterator loop if iterators are used. (gimplify_omp_workshare): Call remove_unused_omp_iterator_vars and build_omp_iterators_loops for OpenMP target expressions. Add loop sequence as argument when calling gimplify_adjust_omp_clauses and building the Gimple statement. * gimplify.h (enter_omp_iterator_loop_context): New prototype. (exit_omp_iterator_loop_context): New prototype. * gsstruct.def (GSS_OMP_TARGET): New. * omp-low.cc (lower_omp_map_iterator_expr): New. (lower_omp_map_iterator_size): New. (finish_omp_map_iterators): New. (lower_omp_target): Add sorry if iterators used with deep mapping. Call lower_omp_map_iterator_expr before assigning to sender ref. Call lower_omp_map_iterator_size before setting the size. Insert iterator loop sequence before the statements for the target clause. * tree-nested.cc (convert_nonlocal_reference_stmt): Walk the iterator loop sequence of OpenMP target statements. (convert_local_reference_stmt): Likewise. (convert_tramp_reference_stmt): Likewise. * tree-pretty-print.cc (dump_omp_iterators): Dump extra iterator information if present. (dump_omp_clause): Call dump_omp_iterators for iterators in map clauses. * tree.cc (omp_clause_num_ops): Add operand for OMP_CLAUSE_MAP. (walk_tree_1): Do not walk last operand of OMP_CLAUSE_MAP. * tree.h (OMP_CLAUSE_HAS_ITERATORS): New. (OMP_CLAUSE_ITERATORS): New. gcc/testsuite/ * c-c++-common/gomp/map-6.c (foo): Amend expected error message. * c-c++-common/gomp/target-map-iterators-1.c: New. * c-c++-common/gomp/target-map-iterators-2.c: New. * c-c++-common/gomp/target-map-iterators-3.c: New. * c-c++-common/gomp/target-map-iterators-4.c: New. libgomp/ * target.c (kind_to_name): New. (gomp_merge_iterator_maps): New. (gomp_map_vars_internal): Call gomp_merge_iterator_maps. Copy address of only the first iteration to target vars. Free allocated variables. * testsuite/libgomp.c-c++-common/target-map-iterators-1.c: New. * testsuite/libgomp.c-c++-common/target-map-iterators-2.c: New. * testsuite/libgomp.c-c++-common/target-map-iterators-3.c: New. Co-authored-by: Andrew Stubbs <ams@baylibre.com>
9 daysopenmp: Refactor handling of iteratorsKwok Cheung Yeung1-10/+3
Move code to calculate the iteration size and to generate the iterator expansion loop into separate functions. Use OMP_ITERATOR_DECL_P to check for iterators in clause declarations. gcc/c-family/ * c-omp.cc (c_finish_omp_depobj): Use OMP_ITERATOR_DECL_P. gcc/c/ * c-typeck.cc (handle_omp_array_sections): Use OMP_ITERATOR_DECL_P. (c_finish_omp_clauses): Likewise. gcc/cp/ * pt.cc (tsubst_omp_clause_decl): Use OMP_ITERATOR_DECL_P. * semantics.cc (handle_omp_array_sections): Likewise. (finish_omp_clauses): Likewise. gcc/ * gimplify.cc (gimplify_omp_affinity): Use OMP_ITERATOR_DECL_P. (compute_omp_iterator_count): New. (build_omp_iterator_loop): New. (gimplify_omp_depend): Use OMP_ITERATOR_DECL_P, compute_omp_iterator_count and build_omp_iterator_loop. * tree-inline.cc (copy_tree_body_r): Use OMP_ITERATOR_DECL_P. * tree-pretty-print.cc (dump_omp_clause): Likewise. * tree.h (OMP_ITERATOR_DECL_P): New macro.
9 daysOpenACC 2.7: Implement reductions for arrays and recordsChung-Lin Tang2-9/+95
This patch is a merge of: https://gcc.gnu.org/pipermail/gcc-patches/2025-February/675222.html This patch implements reductions for arrays, array sections, and struct/record types as according to the OpenACC 2.7 specification. 2025-02-23 Chung-Lin Tang <cltang@baylibre.com> gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_variable_list): Adjust parsing of opening square bracket. (c_parser_omp_clause_reduction): Adjustments for OpenACC-specific cases. * c-typeck.cc (c_oacc_reduction_defined_type_p): New function. (c_oacc_reduction_code_name): Likewise. (c_finish_omp_clauses): Handle OpenACC cases using new functions. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_var_list_no_open): Adjust parsing of opening square bracket. (cp_parser_omp_clause_reduction): Adjustments for OpenACC-specific cases. * semantics.cc (cp_oacc_reduction_defined_type_p): New function. (cp_oacc_reduction_code_name): Likewise. (finish_omp_reduction_clause): Handle OpenACC cases using new functions. gcc/fortran/ChangeLog: * openmp.cc (oacc_reduction_defined_type_p): New function. (resolve_omp_clauses): Adjust OpenACC array reduction error case. Adjust OMP_LIST_REDUCTION case. Use oacc_reduction_defined_type_p for OpenACC. * trans-openmp.cc (gfc_trans_omp_array_reduction_or_udr): Add 'stmtblock_t *block', and 'bool openacc' parameters. Add array and array section handling for openacc case. Adjust part of function to be !openacc only. (gfc_trans_omp_reduction_list): Add 'stmtblock_t *block', and 'bool openacc' parameters, pass to calls to gfc_trans_omp_array_reduction_or_udr. (gfc_trans_omp_array_section): Adjust setting of OMP_CLAUSE_SIZE to only OMP_CLAUSE_MAP clauses. Adjust calculations of decls and bias to use temporary variables instead of tree expression inside clauses. (gfc_trans_omp_clauses): Add 'block' and 'openacc' arguments to calls to gfc_trans_omp_reduction_list. (gfc_trans_omp_do): Pass 'op == EXEC_OACC_LOOP' as 'bool openacc' parameter in call to gfc_trans_omp_clauses. gcc/ChangeLog: * config/gcn/gcn-tree.cc (#include "omp-offload.h"): Add include. (#include "memmodel.h"): Add include. (gcn_array_reduction_buffers): New vec<tree> for holding DECLs for reduction buffer pointer variables. (gcn_lockfull_update): Add pointer type fold_converts. (gcn_reduction_update): Additions for handling ARRAY_TYPE, pointer to ARRAY_TYPE, and RECORD_TYPE reductions. (gcn_goacc_get_worker_red_decl): Adjust parameters to handle non-constant offset case. (gcn_goacc_get_worker_array_reduction_buffer): New function. (gcn_create_if_else_seq): New function. (gcn_create_do_while_loop_seq): New function. (gcn_goacc_reduction_setup): Adjustments to handle arrays and records. (gcn_goacc_reduction_init): Likewise. (gcn_goacc_reduction_fini): Likewise. (gcn_goacc_reduction_teardown): Likewise. * config/nvptx/nvptx.cc (nvptx_gen_shuffle): Properly generate V2SI shuffle using vec_extract op. (nvptx_expand_shared_addr): Adjustments to handle non-constant size. (nvptx_get_shared_red_addr): Adjust type/alignment calculations to use TYPE_SIZE/ALIGN_UNIT instead of machine mode based. (nvptx_get_shared_red_addr): New function with array_max_idx parameter. (nvptx_reduction_update): Additions for handling ARRAY_TYPE, pointer to ARRA_TYPE, and RECORD_TYPE reductions. (nvptx_goacc_reduction_setup): Likewise. (nvptx_goacc_reduction_init): Likewise. (nvptx_goacc_reduction_fini): Likewise. (nvptx_goacc_reduction_teardown): Likewise. * gimplify.cc (gimplify_scan_omp_clauses): Gimplify inside COMPONENT_REF and convert codes for OMP_CLAUSE_REDUCTION cases. Add DECL_P check for do_add/do_add_decl goto case. (gimplify_adjust_omp_clauses): Avoid GOMP_MAP_POINTER OMP_CLAUSE_SIZE handling for OpenACC kernels. Call omp_add_variable for ARRAY_REF index. Peel away array MEM_REF for decl lookup. * omp-low.cc (struct omp_context): Add 'hash_map<tree, tree> *block_vars_map' field. (omp_copy_decl_2): Create/lookup using ctx->block_vars_map first. Add new copy into ctx->block_vars_map. (install_var_field): Add 'bool field_may_exist = false' parameter. Adjust lookup assertions. (delete_omp_context): Add delete of ctx->block_vars_map. (scan_sharing_clauses): Adjust calls to install_var_field. Adjust ARRAY_REF pointer type building to use decl type, rather than generic ptr_type_node. For ARRAY_REFs on offloaded constructs, also add base expression as field lookup key. (omp_reduction_init_op): Add ARRAY_TYPE and RECORD_TYPE init op construction. (oacc_array_reduction_bias): New function. (lower_oacc_reductions): Add array reduction handling code. Arrays use a different mode of IFN parameters, using additional 'array_addr' and 'array_max_idx' arguments. The LHS var is a simple integer for dependency ordering. (lower_omp_target): Adjust 'offload' condition for GOMP_MAP_POINTER case. Generate BUILT_IN_ALLOCA_WITH_ALIGN to create private copy for reductions of non-constant size types. * omp-oacc-neuter-broadcast.cc (worker_single_copy): Add 'hash_set<tree> *array_reduction_base_vars' parameter. Avoid propagation for SSA_NAMEs used for array reduction accesses. (neuter_worker_single): Add 'hash_set<tree> *array_reduction_base_vars' parameter. Adjust recursive calls to self and worker_single_copy. (oacc_do_neutering): Add 'hash_set<tree> *array_reduction_base_vars' parameter. Adjust call to neuter_worker_single. (execute_omp_oacc_neuter_broadcast): Add local 'hash_set<tree> array_reduction_base_vars' declaration. Collect MEM_REF base-pointer SSA_NAMEs of arrays into array_reduction_base_vars. Add '&array_reduction_base_vars' argument to call of oacc_do_neutering. * omp-offload.cc (#include "cfghooks.h"): Add include. (oacc_build_array_copy): New function. (oacc_build_array_copy_loop): New function. (oacc_build_indexed_ssa_loop): New function. (default_goacc_reduction): Adjustments to handle arrays. * omp-offload.h (oacc_build_array_copy): New declaration. (oacc_build_array_copy_loop): New declaration. (oacc_build_indexed_ssa_loop): New declaration. * tree-loop-distribution.cc (generate_memset_builtin): Under OpenACC, when last stmt of pre-header block is a UNIQUE(OACC_FORK) internal-fn, split a new basic block to serve as place of insertion, otherwise may fail later checking because UNIQUE(OACC_FORK) counts as control flow stmt. (generate_memcpy_builtin): Likewise. gcc/testsuite/ChangeLog: * c-c++-common/goacc/readonly-2.c: Adjust test. * c-c++-common/goacc/reduction-9.c: Adjust test. * c-c++-common/goacc/reduction-11.c: New test. * c-c++-common/goacc/reduction-12.c: New test. * c-c++-common/goacc/reduction-13.c: New test. * c-c++-common/goacc/reduction-14.c: New test. * c-c++-common/goacc/reduction-15.c: New test. * c-c++-common/goacc/reduction-16.c: New test. * g++.dg/goacc/reductions-1.C: Adjust test. * gfortran.dg/goacc/array-reduction.f90: Adjust test. * gfortran.dg/goacc/enter-exit-data-2.f90: Adjust test. * gfortran.dg/goacc/finalize-1.f: Adjust test. * gfortran.dg/goacc/kernels-decompose-1.f95: Adjust test. * gfortran.dg/goacc/pr70828.f90: Adjust test. * gfortran.dg/goacc/reduction.f95: Adjust test. * gfortran.dg/gomp/target-enter-exit-data.f90: Adjust test. libgomp/ChangeLog: * testsuite/libgomp.oacc-c-c++-common/reduction.h (check_reduction_array_xx): New macro. (operator_apply): Likewise. (check_reduction_array_op): Likewise. (check_reduction_arraysec_op): Likewise. (function_apply): Likewise. (check_reduction_array_macro): Likewise. (check_reduction_arraysec_macro): Likewise. (check_reduction_xxx_xx_all): Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-3.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-4.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-5.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-structs-1.c: New test. * testsuite/libgomp.oacc-fortran/reduction-10.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-11.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-12.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-13.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-14.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-15.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-16.f90: New test.
9 daysOpenMP: C front end support for "begin declare variant"Sandra Loosemore3-36/+318
gcc/c/ChangeLog * c-decl.cc (current_omp_declare_variant_attribute): Define. * c-lang.h (struct c_omp_declare_variant_attr): Declare. (current_omp_declare_variant_attribute): Declare. * c-parser.cc (c_parser_skip_to_pragma_omp_end_declare_variant): New. (c_parser_translation_unit): Check for "omp begin declare variant" with no matching "end". (c_parser_declaration_or_fndef): Handle functions in "omp begin declare variant" block. (c_finish_omp_declare_variant): Merge context selectors with surrounding "omp begin declare variant". (JOIN_STR): Define. (omp_start_variant_function): New. (omp_finish_variant_function): New. (c_parser_omp_begin): Handle "omp begin declare variant". (c_parser_omp_end): Likewise. Co-Authored-By: Julian Brown <julian@codesourcery.com>
9 daysOpenMP: Add C++ support for 'omp allocate'waffl3x1-1/+1
This patch handles local variables, global variables, as well as static local variables where it is currently practical to do so. For now we sorry on static local variables inside implicit constexpr functions, this includes lambdas in c++17 and up, and inline functions with -fimplicit-constexpr in c++14 and up. I have another patch that fixes most cases, unfortunately there are a few cases that are not fixable without additional redesigns. For function templates Instead of storing the directive directly in a variables 'omp allocate' attribute and substituting into it, this patch adds the OMP_ALLOCATE tree code that gets substituted. This makes it much easier to prevent duplicate diagnostics with an invalid allocator/align clause. This is added to a function template's stmt list and is only used for substitution. It is not added to instantiations of a function template, nor to regular functions. Location information is included in the 'omp allocate' attribute to enhance diagnostics of variables used in multiple allocate directives. While it is possible that this could be added to the c front end, it would require some reworking so it is not included in this patch. It was easy to support this in the c++ front end because it is not practical to wait for a finalized directive to add the 'omp allocate' attribute to vars, nor is it practical to remove it in error cases. Consequentially some extra handling for this needed to be added to gimplify.cc to avoid problems in error cases and prevent conflicts with Fortran specific implementation details. There is a left over band-aid fix in make_rtl_for_nonlocal_decl that only worked for template cases, it probably has no effect at the moment. The problem is make_rtl_for_nonlocal_decl never defers static locals in any kind of constexpr function, including lambdas in c++17, regardless of whether they can be used in a constant expression. I have a lengthy write up of the history of why this is the case and the implications of it all, but it is not directly relevant to this patch. In short, the original reason static locals are not deferred was to fix PR70353 and was added in r6-7642-ge0bffbbb5936be, however in r9-3788-gddd0d18c9c0702 the handling of that case was changed and no longer goes through make_rtl_for_nonlocal_decl. Unfortunately, we can't merely undo what was added, as c++23 static constexpr local variables rely on it, as well as cases with c++17 lambdas that should be disallowed, but aren't. This should never be relevant, As OpenMP directives are not currently allowed in constexpr functions, but as stated above the early processing of static locals happens regardless of whether the function is actually usable in a constant expression. In non templates, this early processing occurs before we have even parsed the allocate directive, causing alignment specified in an align clause to be skipped over entirely. In templates we at least get to add the attribute to mark a var before this happens, so we can use the presence of it to make sure they get deferred. This is the band-aid that is currently present in make_rtl_for_nonlocal_decl, however we currently reject these cases as it is fairly difficult to differentiate whether we are in a regular function or not. We can't just rely on processing_template_decl as it would just error upon instantiation. In hindsight it would probably have worked fine in cp_parser_omp_allocate, but this is supposed to be a temporary measure anyway as I have a follow up patch. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_allocate): Fix typo in diagnostic. gcc/ChangeLog: * cgraphunit.cc (varpool_node::finalize_decl): Add assert. * gimplify.cc (gimplify_bind_expr): Handle C++ specific implementation details. gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Handle OMP_ALLOCATE. * cp-tree.def (OMP_ALLOCATE): New tree code. * cp-tree.h (OMP_ALLOCATE_LOCATION): Define. (OMP_ALLOCATE_VARS): Define. (OMP_ALLOCATE_ALLOCATOR): Define. (OMP_ALLOCATE_ALIGN): Define. (finish_omp_allocate): New function declaration. * decl.cc (make_rtl_for_nonlocal_decl): Work around ICE with implicit constexpr functions. * parser.cc (cp_parser_omp_allocate): Use OMP_CLAUSE_ERROR, add diagnostics for args, call finish_omp_allocate. (cp_parser_omp_construct): Don't handle PRAGMA_OMP_ALLOCATE. (cp_parser_pragma): Comment. * pt.cc (tsubst_stmt): Handle OMP_ALLOCATE, call finish_omp_allocate. * semantics.cc (finish_omp_allocate): New function. * typeck.cc (can_do_nrvo_p): Don't do NRVO for omp allocate vars. libgomp/ChangeLog: * libgomp.texi: Document C++ support. * testsuite/libgomp.c/allocate-4.c: Move to... * testsuite/libgomp.c-c++-common/allocate-4.c: ...here. * testsuite/libgomp.c/allocate-5.c: Move to... * testsuite/libgomp.c-c++-common/allocate-5.c: ...here. * testsuite/libgomp.c/allocate-6.c: Move to... * testsuite/libgomp.c-c++-common/allocate-6.c: ...here. * testsuite/libgomp.c++/allocate-2.C: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/allocate-allocator-handle.h: New header. * c-c++-common/gomp/allocate-5.c: Remove dg-messages for 'sorry', add dg-error for c++. * c-c++-common/gomp/allocate-9.c: Include header, remove dg-messages for 'sorry', add dg-notes for c++, minor refactoring. * c-c++-common/gomp/allocate-10.c: Enable for c++. * c-c++-common/gomp/allocate-11.c: Enable for c++, disable warning. * c-c++-common/gomp/allocate-12.c: Enable for c++, add cases. * c-c++-common/gomp/allocate-14.c: Enable for c++. * c-c++-common/gomp/allocate-15.c: Enable for c++. * c-c++-common/gomp/allocate-16.c: Enable for c++. * c-c++-common/gomp/allocate-17.c: Remove dg-message for 'sorry'. * c-c++-common/gomp/allocate-18.c: Include header, remove dg-message for 'sorry'. * c-c++-common/gomp/allocate-19.c: Remove xfails for c++, remove dg-messages for 'sorry'. * c-c++-common/gomp/allocate-20.c: New test. * c-c++-common/gomp/directive-1.c: Remove dg-message for 'sorry'. * g++.dg/gomp/allocate-allocator-handle.h: New header. * g++.dg/gomp/allocate-5.C: New test. * g++.dg/gomp/allocate-6.C: New test. * g++.dg/gomp/allocate-7.C: New test. * g++.dg/gomp/allocate-8.C: New test. * g++.dg/gomp/allocate-9.C: New test. * g++.dg/gomp/allocate-10.C: New test. * g++.dg/gomp/allocate-11.C: New test. * g++.dg/gomp/allocate-12.C: New test. * g++.dg/gomp/allocate-13.C: New test. * g++.dg/gomp/allocate-14.C: New test. * g++.dg/gomp/allocate-15.C: New test. * g++.dg/gomp/allocate-16.C: New test. * g++.dg/gomp/allocate-17.C: New test. * g++.dg/gomp/allocate-18.C: New test. * g++.dg/gomp/allocate-19.C: New test. * g++.dg/gomp/allocate-20.C: New test. * g++.dg/gomp/allocate-21.C: New test. Signed-off-by: waffl3x <waffl3x@baylibre.com> Co-authored-by: Tobias Burnus <tobias@codesourcery.com>
9 daysOpenMP: Enable 'declare mapper' mappers for 'target update' directivesJulian Brown1-12/+140
This patch enables use of 'declare mapper' for 'target update' directives, for each of C, C++ and Fortran. There are some implementation choices here and some "read-between-the-lines" consequences regarding this functionality, as follows: * It is possible to invoke a mapper which contains clauses that don't make sense for a given 'target update' operation. E.g. if a mapper definition specifies a "from:" mapping and the user does "target update to(...)" which triggers that mapper, the resulting map kind (OpenMP 5.2, "Table 5.3: Map-Type Decay of Map Type Combinations") is "alloc" (and for the inverse case "release"). For such cases, an unconditional warning is issued and the map clause in question is dropped from the mapper expansion. (Other choices might be to make this an error, or to do the same thing but silently, or warn only given some special option.) * The array-shaping operator is *permitted* for map clauses within 'declare mapper' definitions. That is because such mappers may be used for 'target update' directives, where the array-shaping operator is permitted. I think that makes sense, depending on the semantic model of how and when substitution is supposed to take place, but I couldn't find such behaviour explicitly mentioned in the spec (as of 5.2). If the mapper is triggered by a different directive ("omp target", "omp target data", etc.), an error will be raised. Support is also added for the "mapper" modifier on to/from clauses for all three base languages. 2023-08-10 Julian Brown <julian@codesourcery.com> gcc/c-family/ * c-common.h (c_omp_region_type): Add C_ORT_UPDATE and C_ORT_OMP_UPDATE codes. * c-omp.cc (omp_basic_map_kind_name): New function. (omp_instantiate_mapper): Add LOC parameter. Add 'target update' support. (c_omp_instantiate_mappers): Add 'target update' support. gcc/c/ * c-parser.cc (c_parser_omp_variable_list): Support array-shaping operator in 'declare mapper' definitions. (c_parser_omp_clause_map): Pass C_ORT_OMP_DECLARE_MAPPER to c_parser_omp_variable_list in mapper definitions. (c_parser_omp_clause_from_to): Add parsing for mapper modifier. (c_parser_omp_target_update): Instantiate mappers. gcc/cp/ * parser.cc (cp_parser_omp_var_list_no_open): Support array-shaping operator in 'declare mapper' definitions. (cp_parser_omp_clause_from_to): Add parsing for mapper modifier. (cp_parser_omp_clause_map): Pass C_ORT_OMP_DECLARE_MAPPER to cp_parser_omp_var_list_no_open in mapper definitions. (cp_parser_omp_target_update): Instantiate mappers. gcc/fortran/ * openmp.cc (gfc_match_motion_var_list): Add parsing for mapper modifier. (gfc_match_omp_clauses): Adjust error handling for changes to gfc_match_motion_var_list. (gfc_omp_instantiate_mapper): Add code argument to get proper location for diagnostic. (gfc_omp_instantiate_mappers): Adjust for above change. * trans-openmp.cc (gfc_trans_omp_clauses): Use correct ref for update operations. (gfc_trans_omp_target_update): Instantiate mappers. gcc/testsuite/ * c-c++-common/gomp/declare-mapper-17.c: New test. * c-c++-common/gomp/declare-mapper-19.c: New test. * gfortran.dg/gomp/declare-mapper-24.f90: New test. * gfortran.dg/gomp/declare-mapper-26.f90: Uncomment 'target update' part of test. * gfortran.dg/gomp/declare-mapper-27.f90: New test. libgomp/ * testsuite/libgomp.c-c++-common/declare-mapper-18.c: New test. * testsuite/libgomp.fortran/declare-mapper-25.f90: New test. * testsuite/libgomp.fortran/declare-mapper-28.f90: New test. Co-Authored-By: Andrew Stubbs <ams@baylibre.com> Co-Authored-By: Kwok Cheung Yeung <kcyeung@baylibre.com> Co-Authored-By: Sandra Loosemore <sloosemore@baylibre.com>
9 daysOpenMP: Array shaping operator and strided "target update" for CJulian Brown3-44/+486
Following the similar support for C++, here is the C implementation for the OpenMP 5.0 array-shaping operator, and for strided and rectangular updates for "target update". Much of the implementation is shared with the C++ support added by the previous patch. Some details of parsing necessarily differ for C, but the general ideas are the same. This version of the patch has been rebased and contains a couple of minor fixes relative to versions posted previously. 2023-09-05 Julian Brown <julian@codesourcery.com> gcc/c/ * c-parser.cc (c_parser_braced_init): Disallow array-shaping operator in braced init. (c_parser_conditional_expression): Disallow array-shaping operator in conditional expression. (c_parser_cast_expression): Add array-shaping operator support. (c_parser_postfix_expression): Disallow array-shaping operator in statement expressions. (c_parser_postfix_expression_after_primary): Add OpenMP array section stride support. (c_parser_expr_list): Disallow array-shaping operator in expression lists. (c_array_type_nelts_total): New function. (c_parser_omp_variable_list): Support array-shaping operator. (c_parser_omp_target_update): Recognize GOMP_MAP_TO_GRID and GOMP_MAP_FROM_GRID map kinds as well as OMP_CLAUSE_TO/OMP_CLAUSE_FROM. * c-tree.h (c_omp_array_shaping_op_p, c_omp_has_array_shape_p): New extern declarations. (create_omp_arrayshape_type): Add prototype. * c-typeck.cc (c_omp_array_shaping_op_p, c_omp_has_array_shape_p): New globals. (build_omp_array_section): Permit integral types, not just integer constants, when creating array types for array sections. (create_omp_arrayshape_type): New function. (handle_omp_array_sections_1): Add DISCONTIGUOUS parameter. Add strided/rectangular array section support. (omp_array_section_low_bound): New function. (handle_omp_array_sections): Add DISCONTIGUOUS parameter. Add strided/rectangular array section support. (c_finish_omp_clauses): Update calls to handle_omp_array_sections. Handle discontiguous updates. gcc/testsuite/ * gcc.dg/gomp/bad-array-shaping-c-1.c: New test. * gcc.dg/gomp/bad-array-shaping-c-2.c: New test. * gcc.dg/gomp/bad-array-shaping-c-3.c: New test. * gcc.dg/gomp/bad-array-shaping-c-4.c: New test. * gcc.dg/gomp/bad-array-shaping-c-5.c: New test. * gcc.dg/gomp/bad-array-shaping-c-6.c: New test. * gcc.dg/gomp/bad-array-shaping-c-7.c: New test. libgomp/ * testsuite/libgomp.c-c++-common/array-shaping-14.c: New test. * testsuite/libgomp.c/array-shaping-1.c: New test. * testsuite/libgomp.c/array-shaping-2.c: New test. * testsuite/libgomp.c/array-shaping-3.c: New test. * testsuite/libgomp.c/array-shaping-4.c: New test. * testsuite/libgomp.c/array-shaping-5.c: New test. * testsuite/libgomp.c/array-shaping-6.c: New test.
9 daysOpenMP: Support strided and shaped-array updates for C++Julian Brown3-19/+41
This patch adds support for OpenMP 5.0 strided updates and the array-shaping operator ("([x][y][z]) foo[0:n]..."). This is mostly for C++ only so far, though necessary changes have been made to the C FE to adjust for changes to shared data structures. In terms of the implementation of various bits: - The OMP_ARRAY_SECTION tree code has been extended to take a 'stride' argument, and changes have been made throughout semantics.cc, etc. to take the new field into account -- including bounds checking. - A new type of cast operator has been added to represent the OpenMP array-shaping operator: OMP_ARRAYSHAPE_CAST_EXPR (1). - The address tokenization mechanism from previous patches has been extended with two new access kinds to represent noncontiguous array updates. - New mapping kinds have been added to represent noncontiguous updates: those which may be subject to array shaping, or have non-unit strides. These are processed by omp-low.cc into a kind of descriptor that is passed to the libgomp runtime (2). The current patch reuses an extended version of the helper code for omp_target_memcpy_rect, which may generate very many small host-device or device-host copies. (The "descriptor" has also been designed so reusing that functionality is relatively straightforward.) Optimising those multiple copies, e.g. by packing them into a single transfer when it would be beneficial, is left as the subject of a future patch. This patch has some adjustments to the omp-low.cc code after Chung-Lin's patch "OpenMP 5.0: Allow multiple clauses mapping same variable" (325f085897efca59879a64704ab15f1763ecb807), relative to the version last posted for mainline. Notes: (1) In a bit more detail: the array-shaping operator has the same precedence as a C-style cast, but applies to the whole expression, including array-section specifiers. We parse it initially as if it applies to the "value" of the whole expression: ([x][y]) ptr[0:10:2][1:5:2] i.e., something like: ([x][y]) (ptr[0:10:2][1:5:2]) or as if the cast applies to the innermost/right-hand side array section. Then, a little later in parsing (cp_parser_omp_var_list_no_open), we rewrite it to apply to the inner pointer instead: (([x][y]) ptr)[0:10:2][1:5:2] and that means a genuine multi-dimensional array or an array-shaped pointer can be handled pretty much the same for the rest of compilation. We use VIEW_CONVERT_EXPR for the "cast", unless we're processing a template definition, where we use a new tree code instead. (2) The new map kinds work like this. An update directive starts out with OMP_CLAUSE_TO or OMP_CLAUSE_FROM clauses representing the block in question and the direction of the needed transfer. If we detect a noncontiguous update, we emit a list of mapping nodes (type OMP_CLAUSE_MAP, with new kinds, so the "mapping group" machinery in gimplify.cc can be reused): OMP_CLAUSE_TO --> GOMP_MAP_TO_GRID (VIEW_CONVERT_EXPR<int[x][y]>(ptr) [len: <element-size>]) GOMP_MAP_GRID_DIM 0 [len: 10] (i.e. [0:10:2]) GOMP_MAP_GRID_STRIDE 2 GOMP_MAP_GRID_DIM 1 [len: 5] (i.e. [1:5:2]) GOMP_MAP_GRID_STRIDE 2 During omp-low.cc, this sequence is reformulated into: GOMP_MAP_TO_GRID (ptr) [len: <whole array size>] GOMP_MAP_TO_PSET (&ptr_desc [len: <desc size>]) "ptr_desc" is a struct, stored statically or constructed on the (host) stack, containing arrays representing the size of the whole array, the rectangular subregion to transfer, and the stride with which to walk over elements in each dimension. 2023-07-03 Julian Brown <julian@codesourcery.com> gcc/c-family/ * c-omp.cc (c_omp_address_inspector::map_supported_p): Support VIEW_CONVERT_EXPR and ADDR_EXPR codes. (omp_expand_grid_dim): New function. (omp_handle_noncontig_array): New function. (c_omp_address_inspector:expand_array_base): Support noncontiguous array updates. (c_omp_address_inspector::expand_component_selector): Support noncontiguous array updates. * c-pretty-print.cc (c_pretty_printer::postfix_expression): Add OMP_ARRAY_SECTION stride support. gcc/c/ * c-parser.cc (c_parser_postfix_expression_after_primary): Dummy stride support (for now). (struct omp_dim): Add stride support. (c_parser_omp_variable_list): Likewise. * c-tree.h (build_omp_array_section): Update prototype. * c-typeck.cc (mark_exp_read): Add stride support for OMP_ARRAY_SECTION. (build_omp_array_section): Add stride support. (handle_omp_array_sections_1): Add minimal stride support. gcc/cp/ * cp-objcp-common.cc (cp_common_init_ts): Add array-shape cast support. * cp-tree.def (OMP_ARRAYSHAPE_CAST_EXPR): Add tree code. * cp-tree.h (DECLTYPE_FOR_OMP_ARRAYSHAPE_CAST): Add flag. (cp_omp_create_arrayshape_type, cp_build_omp_arrayshape_cast): Add prototypes. (grok_omp_array_section, build_omp_array_section): Add stride parameters. * decl.cc (create_anon_array_type): New function. (cp_omp_create_arrayshape_type): New function. * decl2.cc (grok_omp_array_section): Add stride parameter. (min_vis_expr_r): Add OMP_ARRAYSHAPE_CAST_EXPR support. * error.cc (dump_expr): Add stride support for OMP_ARRAY_SECTION. * mangle.cc (write_expression): Add OMP_ARRAYSHAPE_CAST_EXPR support. * operators.def (OMP_ARRAYSHAPE_CAST_EXPR): Add. * parser.cc (cp_parser_new): Initialise omp_array_shaping_op_p and omp_has_array_shape_p fields. (cp_parser_statement_expr): Don't allow array shaping op in statement exprs. (cp_parser_postfix_open_square_expression): Add stride parsing for array sections. Use array section code to represent array refs if we have an array-shaping operator. (cp_parser_parenthesized_expression_list): Don't allow array-shaping op here. (cp_parser_cast_expression): Add array-shaping operator parsing. (cp_parser_lambda_expression): Don't allow array-shaping op in lambda body. (cp_parser_braced_list): Don't allow array-shaping op in braced list. (struct omp_dim): Add stride field. (cp_parser_var_list_no_open): Add stride/array shape support. (cp_parser_omp_target_update): Handle noncontiguous updates. * parser.h (cp_parser): Add omp_array_shaping_op_p and omp_has_array_shape_p fields. * pt.cc (tsubst): Add array-shape cast support. (tsubst_copy, tsubst_copy_and_build): Likewise. Add stride support for OMP_ARRAY_SECTION. (tsubst_omp_clause_decl): Add stride support for OMP_ARRAY_SECTION. * semantics.cc (handle_omp_array_sections_1): Add DISCONTIGUOUS parameter and stride support. (omp_array_section_low_bound): New function. (handle_omp_array_sections): Add DISCONTIGUOUS parameter and stride support. (finish_omp_clauses): Update calls to handle_omp_array_sections, and add noncontiguous array update support. (cp_build_omp_arrayshape_cast): New function. * typeck.cc (structural_comptypes): Add array-shape cast support. (build_omp_array_section): Add stride parameter. (check_for_casting_away_constness): Add OMP_ARRAYSHAPE_CAST_EXPR support. gcc/ * gimplify.cc (omp_group_last, omp_group_base): Add GOMP_MAP_TO_GRID, GOMP_MAP_FROM_GRID support. (gimplify_adjust_omp_clauses): Support new GOMP_MAP_GRID_DIM, GOMP_MAP_GRID_STRIDE mapping nodes. Don't crash on e.g. misuse of ADDR_EXPR in mapping clauses. * omp-general.cc (omp_parse_noncontiguous_array): New function. (omp_parse_access_method): Add noncontiguous array support. (omp_parse_structure_base): Add array-shaping support. (debug_omp_tokenized_addr): Add ACCESS_NONCONTIG_ARRAY, ACCESS_NONCONTIG_REF_TO_ARRAY token support. * omp-general.h (access_method_kinds): Add ACCESS_NONCONTIG_ARRAY and ACCESS_NONCONTIG_REF_TO_ARRAY access kinds. * omp-low.cc (omp_noncontig_descriptor_type): New function. (scan_sharing_clauses): Support noncontiguous array updates. (lower_omp_target): Likewise. * tree-pretty-print.cc (dump_omp_clause): Add GOMP_MAP_TO_GRID, GOMP_MAP_FROM_GRID, GOMP_MAP_GRID_DIM, GOMP_MAP_GRID_STRIDE map kinds. (dump_generic_node): Add stride support for OMP_ARRAY_SECTION. * tree.def (OMP_ARRAY_SECTION): Add stride argument. include/ * gomp-constants.h (gomp_map_kind): Add GOMP_MAP_TO_GRID, GOMP_MAP_FROM_GRID, GOMP_MAP_GRID_DIM, GOMP_MAP_GRID_STRIDE map kinds. gcc/testsuite/ * g++.dg/gomp/array-shaping-1.C: New test. * g++.dg/gomp/array-shaping-2.C: New test. * g++.dg/gomp/bad-array-shaping-1.C: New test. * g++.dg/gomp/bad-array-shaping-2.C: New test. * g++.dg/gomp/bad-array-shaping-3.C: New test. * g++.dg/gomp/bad-array-shaping-4.C: New test. * g++.dg/gomp/bad-array-shaping-5.C: New test. * g++.dg/gomp/bad-array-shaping-6.C: New test. * g++.dg/gomp/bad-array-shaping-7.C: New test. * g++.dg/gomp/bad-array-shaping-8.C: New test. libgomp/ * libgomp.h (omp_noncontig_array_desc): New struct. * target.c (omp_target_memcpy_rect_worker): Add stride array parameter. Forward declare. Add STRIDES parameter and strided update support. (gomp_update): Add noncontiguous (strided/shaped) update support. * testsuite/libgomp.c++/array-shaping-1.C: New test. * testsuite/libgomp.c++/array-shaping-2.C: New test. * testsuite/libgomp.c++/array-shaping-3.C: New test. * testsuite/libgomp.c++/array-shaping-4.C: New test. * testsuite/libgomp.c++/array-shaping-5.C: New test. * testsuite/libgomp.c++/array-shaping-6.C: New test. * testsuite/libgomp.c++/array-shaping-7.C: New test. * testsuite/libgomp.c++/array-shaping-8.C: New test. * testsuite/libgomp.c++/array-shaping-9.C: New test. * testsuite/libgomp.c++/array-shaping-10.C: New test. * testsuite/libgomp.c++/array-shaping-11.C: New test. * testsuite/libgomp.c++/array-shaping-12.C: New test. * testsuite/libgomp.c++/array-shaping-13.C: New test.
9 daysOpenMP: Allow complete replacement of clause during map/to/from expansionJulian Brown1-16/+29
At present, map/to/from clauses on OpenMP "target" directives may be expanded into several mapping nodes if they describe array sections with pointer or reference bases, or similar. This patch allows the original clause to be replaced during that expansion, mostly by passing the list pointer to the node to various functions rather than the node itself. This is needed by the following patch. There shouldn't be any functional changes introduced by this patch itself. 2023-09-05 Julian Brown <julian@codesourcery.com> gcc/c-family/ * c-common.h (expand_array_base, expand_component_selector, expand_map_clause): Adjust member declarations. * c-omp.cc (omp_expand_access_chain): Pass and return pointer to clause. (c_omp_address_inspector::expand_array_base): Likewise. (c_omp_address_inspector::expand_component_selector): Likewise. (c_omp_address_inspector::expand_map_clause): Likewise. gcc/c/ * c-typeck.cc (handle_omp_array_sections): Pass pointer to clause to process instead of clause. (c_finish_omp_clauses): Update calls to handle_omp_array_sections. Handle cases where initial clause might be replaced. gcc/cp/ * semantics.cc (handle_omp_array_sections): Pass pointer to clause instead of clause. Add PNEXT return parameter for next clause in list to process. (finish_omp_clauses): Update calls to handle_omp_array_sections. Handle cases where initial clause might be replaced.
9 daysOpenMP: Expand "declare mapper" mappers for target {enter,exit,} data directivesJulian Brown2-4/+8
This patch allows 'declare mapper' mappers to be used on 'omp target data', 'omp target enter data' and 'omp target exit data' directives. For each of these, only explicit mappings are supported, unlike for 'omp target' directives where implicit uses of variables inside an offload region might trigger mappers also. Each of C, C++ and Fortran are supported. The patch also adjusts 'map kind decay' to match OpenMP 5.2 semantics, which is particularly important with regard to 'exit data' operations. 2023-07-06 Julian Brown <julian@codesourcery.com> gcc/c-family/ * c-common.h (c_omp_region_type): Add C_ORT_EXIT_DATA, C_ORT_OMP_EXIT_DATA. (c_omp_instantiate_mappers): Add region type parameter. * c-omp.cc (omp_split_map_kind, omp_join_map_kind, omp_map_decayed_kind): New functions. (omp_instantiate_mapper): Add ORT parameter. Implement map kind decay for instantiated mapper clauses. (c_omp_instantiate_mappers): Add ORT parameter, pass to omp_instantiate_mapper. gcc/c/ * c-parser.cc (c_parser_omp_target_data): Instantiate mappers for 'omp target data'. (c_parser_omp_target_enter_data): Instantiate mappers for 'omp target enter data'. (c_parser_omp_target_exit_data): Instantiate mappers for 'omp target exit data'. (c_parser_omp_target): Add c_omp_region_type argument to c_omp_instantiate_mappers call. * c-tree.h (c_omp_instantiate_mappers): Remove spurious prototype. gcc/cp/ * parser.cc (cp_parser_omp_target_data): Instantiate mappers for 'omp target data'. (cp_parser_omp_target_enter_data): Instantiate mappers for 'omp target enter data'. (cp_parser_omp_target_exit_data): Instantiate mappers for 'omp target exit data'. (cp_parser_omp_target): Add c_omp_region_type argument to c_omp_instantiate_mappers call. * pt.cc (tsubst_omp_clauses): Instantiate mappers for OMP regions other than just C_ORT_OMP_TARGET. (tsubst_expr): Update call to tsubst_omp_clauses for OMP_TARGET_UPDATE, OMP_TARGET_ENTER_DATA, OMP_TARGET_EXIT_DATA stanza. * semantics.cc (cxx_omp_map_array_section): Avoid calling build_array_ref for non-array/non-pointer bases (error reported already). gcc/fortran/ * trans-openmp.cc (omp_split_map_op, omp_join_map_op, omp_map_decayed_kind): New functions. (gfc_trans_omp_instantiate_mapper): Add CD parameter. Implement map kind decay. (gfc_trans_omp_instantiate_mappers): Add CD parameter. Pass to above function. (gfc_trans_omp_target_data): Instantiate mappers for 'omp target data'. (gfc_trans_omp_target_enter_data): Instantiate mappers for 'omp target enter data'. (gfc_trans_omp_target_exit_data): Instantiate mappers for 'omp target exit data'. gcc/testsuite/ * c-c++-common/gomp/declare-mapper-15.c: New test. * c-c++-common/gomp/declare-mapper-16.c: New test. * g++.dg/gomp/declare-mapper-1.C: Adjust expected scan output. * gfortran.dg/gomp/declare-mapper-22.f90: New test. * gfortran.dg/gomp/declare-mapper-23.f90: New test.
9 daysOpenMP: Support OpenMP 5.0 "declare mapper" directives for CJulian Brown5-17/+466
This patch adds support for "declare mapper" directives (and the "mapper" modifier on "map" clauses) for C. 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-3.c: Enable for C. * c-c++-common/gomp/declare-mapper-4.c: Likewise. * 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.
9 daysOpenMP: Add uses_allocators supportTobias Burnus2-1/+320
This adds middle end support for uses_allocators, wires Fortran to use it and add C/C++ parsing support. gcc/ChangeLog: * builtin-types.def (BT_FN_VOID_PTRMODE): Add. (BT_FN_PTRMODE_PTRMODE_INT_PTR): Add. * gimplify.cc (gimplify_bind_expr): Diagnose missing uses_allocators clause. (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_workshare): Handle uses_allocators. * omp-builtins.def (BUILT_IN_OMP_INIT_ALLOCATOR, BUILT_IN_OMP_DESTROY_ALLOCATOR): Add. * omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_USES_ALLOCATORS and OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR clauses. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_USES_ALLOCATORS. * tree.cc (omp_clause_num_ops, omp_clause_code_name): Likewise. * tree-pretty-print.cc (dump_omp_clause): Handle it. * tree.h (OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR, OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE, OMP_CLAUSE_USES_ALLOCATORS_TRAITS): New. gcc/c-family/ChangeLog: * c-omp.cc (c_omp_split_clauses): Hande uses_allocators. * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_uses_allocators): New. (c_parser_omp_clause_name, c_parser_omp_all_clauses, OMP_TARGET_CLAUSE_MASK): Handle uses_allocators. * c-typeck.cc (c_finish_omp_clauses): Likewise. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_clause_uses_allocators): New. (cp_parser_omp_clause_name, cp_parser_omp_all_clauses, OMP_TARGET_CLAUSE_MASK): Handle uses_allocators. * semantics.cc (finish_omp_clauses): Likewise. gcc/fortran/ChangeLog: * trans-array.cc (gfc_conv_array_initializer): Set PURPOSE when building constructor for get_initialized_tmp_var. * trans-openmp.cc (gfc_trans_omp_clauses): Handle uses_allocators. * types.def (BT_FN_VOID_PTRMODE, BT_FN_PTRMODE_PTRMODE_INT_PTR): Add. libgomp/ChangeLog: * testsuite/libgomp.c++/c++.exp (check_effective_target_c, check_effective_target_c++): Add. * testsuite/libgomp.c/c.exp (check_effective_target_c, check_effective_target_c++): Add. * testsuite/libgomp.fortran/uses_allocators_2.f90: Remove 'sorry'. * testsuite/libgomp.c-c++-common/uses_allocators-1.c: New test. * testsuite/libgomp.c-c++-common/uses_allocators-2.c: New test. * testsuite/libgomp.c-c++-common/uses_allocators-3.c: New test. * testsuite/libgomp.c-c++-common/uses_allocators-4.c: New test. * testsuite/libgomp.fortran/uses_allocators_3.f90: New test. * testsuite/libgomp.fortran/uses_allocators_4.f90: New test. * testsuite/libgomp.fortran/uses_allocators_5.f90: New test. * testsuite/libgomp.fortran/uses_allocators_6.f90: New test. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-1.f90: Add uses_allocators. * gfortran.dg/gomp/scope-6.f90: Update dg-scan-tree-dump. * c-c++-common/gomp/uses_allocators-1.c: New test. * c-c++-common/gomp/uses_allocators-2.c: New test. * gfortran.dg/gomp/uses_allocators-1.f90: New test.
9 daysOpenMP 5.0: Allow multiple clauses mapping same variableChung-Lin Tang1-1/+1
This is a merge of: https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562081.html This patch now allows multiple clauses on the same construct to map the same variable, which was not valid in OpenMP 4.5, but now allowed in 5.0. This may possibly reverted/updated when a final patch is approved for mainline. gcc/c/ChangeLog * c-typeck.cc (c_finish_omp_clauses): Adjust to allow duplicate mapped variables for OpenMP. gcc/cp/ChangeLog * semantics.cc (finish_omp_clauses): Adjust to allow duplicate mapped variables for OpenMP. gcc/ChangeLog * omp-low.cc (install_var_field): Add new 'tree key_expr = NULL_TREE' default parameter. Set splay-tree lookup key to key_expr instead of var if key_expr is non-NULL. Adjust call to install_parm_decl. Update comments. (scan_sharing_clauses): Use clause tree expression as splay-tree key for map/to/from and OpenACC firstprivate cases when installing the variable field into the send/receive record type. (maybe_lookup_field_in_outer_ctx): Add code to search through construct clauses instead of entirely based on splay-tree lookup. (lower_oacc_reductions): Adjust to find map-clause of reduction variable, then create receiver-ref. (lower_omp_target): Adjust to lookup var field using clause expression. gcc/testsuite/ChangeLog * c-c++-common/gomp/clauses-2.c: Adjust testcase. * c-c++-common/gomp/map-6.c: Adjust testcase. Co-Authored-By: Paul-Antoine Arras <parras@baylibre.com>
9 daysVarious OpenACC reduction enhancements - FE changesJulian Brown2-21/+30
gcc/c/ChangeLog * c-parser.cc (c_parser_omp_variable_list): New c_omp_region_type argument. Use it to specialize handling of OMP_CLAUSE_REDUCTION for OpenACC. (c_parser_omp_var_list_parens): Add region-type argument to call. (c_parser_oacc_data_clause): Likewise. (c_parser_oacc_data_clause_deviceptr): Likewise. (c_parser_omp_clause_reduction): Change is_omp boolean parameter to c_omp_region_type. Update call to c_parser_omp_variable_list. (c_parser_omp_clause_map): Update call to c_parser_omp_variable_list. (c_parser_omp_clause_from_to): Likewise. (c_parser_omp_clause_init): Likewise. (c_parser_oacc_all_clauses): Update calls to c_parser_omp_clause_reduction. (c_parser_omp_all_clauses): Likewise. (c_parser_oacc_cache): Update call to c_parser_omp_variable_list. * c-typeck.cc (c_finish_omp_clauses): Emit an error on orphan OpenACC gang reductions. Suppress user-defined reduction error for OpenACC. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_var_list_no_open): New c_omp_region_type argument. Use it to specialize handling of OMP_CLAUSE_REDUCTION for OpenACC. (cp_parser_omp_var_list): Add c_omp_region_type argument. Update call to cp_parser_omp_var_list_no_open. (cp_parser_oacc_data_clause): Update call to cp_parser_omp_var_list_no_open. (cp_parser_omp_clause_reduction): Change is_omp boolean parameter to c_omp_region_type. Update call to cp_parser_omp_var_list_no_open. (cp_parser_omp_clause_from_to): Update call to cp_parser_omp_clause_var_list_no_open. (cp_parser_omp_clause_map): Likewise. (cp_parser_omp_clause_init): Likewise. (cp_parser_oacc_all_clauses): Update call to cp_parser_omp_clause_reduction. (cp_parser_omp_all_clauses): Likewise. * semantics.cc (finish_omp_reduction_clause): Add c_omp_region_type argument. Suppress user-defined reduction error for OpenACC. (finish_omp_clauses): Update call to finish_omp_reduction_clause. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_omp_clause_copy_ctor): Permit reductions. Co-Authored-By: Cesar Philippidis <cesar@codesourcery.com> Co-Authored-By: Nathan Sidwell <nathan@acm.org> Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
9 daysNon-contiguous array support patches [PR76739]Chung-Lin Tang1-5/+45
This is based on OG14 commit b143c1c447945ce05903ff1360ead97774dfce4b, which was based from v4, posted upstream here: https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543437.html It also incorporates a number of follow-up bug and bit-rot fixes, OG14 commits e11726d3467543de45448097dde27ba34bf04bfe 87ea4de1c4a360d5d62357491a41811213f4528c 151fc161d0ed640048444ca18f9325e3d2e03e99 628a000bdbf63252c2ede13ccab8e99a19769866 11263c048d39ab1d6a11067b18674bf8307bbbf5 8c1068bbe3e52529bede5466a43af8d98f38dac2 gcc/c/ChangeLog PR other/76739 * c-typeck.cc (handle_omp_array_sections_1): Add 'bool &non_contiguous' parameter, adjust recursive call site, add cases for allowing pointer based multi-dimensional arrays for OpenACC. Reject non-DECL base-pointer cases as unsupported. (handle_omp_array_sections): Adjust handle_omp_array_sections_1 call, handle non-contiguous case to create dynamic array map. gcc/cp/ChangeLog PR other/76739 * semantics.cc (handle_omp_array_sections_1): Add 'bool &non_contiguous' parameter, adjust recursive call site, add cases for allowing pointer based multi-dimensional arrays for OpenACC. Reject non-DECL base-pointer cases as unsupported. (handle_omp_array_sections): Adjust handle_omp_array_sections_1 call, handle non-contiguous case to create dynamic array map. gcc/fortran/ChangeLog PR other/76739 * f95-lang.cc (DEF_FUNCTION_TYPE_VAR_5): New symbol. * types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type. gcc/ChangeLog PR other/76739 * builtin-types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type. * gimplify.cc (omp_group_base): Handle GOMP_MAP_NONCONTIG_ARRAY_*. (gimplify_scan_omp_clauses): Handle OMP_TARGET_UPDATE. (gimplify_adjust_omp_clauses): Skip gimplification of OMP_CLAUSE_SIZE of non-contiguous array maps (which is a TREE_LIST). * omp-builtins.def (BUILT_IN_GOACC_DATA_START): Adjust function type to new BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR. * omp-expand.cc (expand_omp_target): Add non-contiguous array descriptor pointers to variadic arguments. * omp-low.cc (append_field_to_record_type): New function. (create_noncontig_array_descr_type): Likewise. (create_noncontig_array_descr_init_code): Likewise. (scan_sharing_clauses): For non-contiguous array map kinds, check for supported dimension structure, and install non-contiguous array variable into current omp_context. (reorder_noncontig_array_clauses): New function. (scan_omp_target): Call reorder_noncontig_array_clauses to place non-contiguous array map clauses at beginning of clause sequence. (lower_omp_target): Add handling for non-contiguous array map kinds, add all created non-contiguous array descriptors to gimple_omp_target_data_arg. * tree-pretty-print.cc (dump_omp_clause): Handle GOMP_MAP_NONCONTIG_ARRAY_*. gcc/testsuite/ChangeLog PR other/76739 * c-c++-common/goacc/data-clause-1.c (foo): Remove expected message. * c-c++-common/goacc/noncontig_array-1.c: New test. * g++.dg/goacc/data-clause-1.C (foo): Remove expected message. include/ChangeLog PR other/76739 * gomp-constants.h (GOMP_MAP_FLAG_SPECIAL_3): Define. (enum gomp_map_kind): Add GOMP_MAP_NONCONTIG_ARRAY, GOMP_MAP_NONCONTIG_ARRAY_TO, GOMP_MAP_NONCONTIG_ARRAY_FROM, GOMP_MAP_NONCONTIG_ARRAY_TOFROM, GOMP_MAP_NONCONTIG_ARRAY_FORCE_TO, GOMP_MAP_NONCONTIG_ARRAY_FORCE_FROM, GOMP_MAP_NONCONTIG_ARRAY_FORCE_TOFROM, GOMP_MAP_NONCONTIG_ARRAY_ALLOC, GOMP_MAP_NONCONTIG_ARRAY_FORCE_ALLOC, GOMP_MAP_NONCONTIG_ARRAY_FORCE_PRESENT. (GOMP_MAP_NONCONTIG_ARRAY_P): Define. libgomp/ChangeLog PR other/76739 * libgomp.h (gomp_map_vars_openacc): New function declaration. * libgomp_g.h (GOACC_data_start): Add variadic '...' to declaration. * oacc-int.h (struct goacc_ncarray_dim): New struct declaration. (struct goacc_ncarray_descr_type): Likewise. (struct goacc_ncarray): Likewise. (struct goacc_ncarray_info): Likewise. (goacc_noncontig_array_create_ptrblock): New function declaration. * oacc-parallel.c (goacc_noncontig_array_count_rows): New function. (goacc_noncontig_array_compute_sizes): Likewise. (goacc_noncontig_array_fill_rows_1): Likewise. (goacc_noncontig_array_fill_rows): Likewise. (goacc_process_noncontiguous_arrays): Likewise. (goacc_noncontig_array_create_ptrblock): Likewise. (GOACC_parallel_keyed): Use goacc_process_noncontiguous_arrays to handle non-contiguous array descriptors at end of varargs, adjust to use gomp_map_vars_openacc. (GOACC_data_start): Likewise. Adjust function type to accept varargs. * target.c (gomp_map_vars_internal): Add struct goacc_ncarray_info * nca_info parameter, add handling code for non-contiguous arrays. (gomp_map_vars_openacc): Add new function for specialization of gomp_map_vars_internal for OpenACC structured region usage. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-3.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-4.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-utils.h: Support header for new tests. Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com> Co-Authored-By: Paul-Antoine Arras <parras@baylibre.com>
2025-05-03Daily bump.GCC Administrator1-0/+8
2025-05-02c: Fix up RAW_DATA_CST handling in check_constexpr_init [PR120057]Jakub Jelinek1-2/+18
The pr120057-1.c testcase is incorrectly rejected since r15-4377 (and for a while it also ICEd after the error), i.e. the optimization of large C initializers using RAW_DATA_CST. Similarly, the embed-18.c testcase is incorrectly rejected since the embed support has been introduced and RAW_DATA_CST used for that. The callers of check_constexpr_init (store_init_value and output_init_element) compute int_const_expr as int_const_expr = (TREE_CODE (init) == INTEGER_CST && !TREE_OVERFLOW (init) && INTEGRAL_TYPE_P (TREE_TYPE (init))); but that is only passed through down to check_constexpr_init. I think tweaking those 2 callers to also allow RAW_DATA_CST for int_const_expr when check_constexpr_init needs top special case it no matter what would be larger, so the patch just changes check_constexpr_init to deal with RAW_DATA_CST in the initializers. For TYPE_UNSIGNED char precision integral types RAW_DATA_CST is always valid, for !TYPE_UNSIGNED we need to check for 128-255 values being turned into negative ones. 2025-05-02 Jakub Jelinek <jakub@redhat.com> PR c/120057 * c-typeck.cc (check_constexpr_init): Handle RAW_DATA_CST. * gcc.dg/cpp/embed-18.c: New test. * gcc.dg/pr120057-1.c: New test. * gcc.dg/pr120057-2.c: New test. (cherry picked from commit e81f2f4855876c5d85ab9870c5a150ee1a59ee73)
2025-04-25Update ChangeLog and version files for releasereleases/gcc-15.1.0Jakub Jelinek1-0/+4
2025-04-16Daily bump.GCC Administrator1-0/+6
2025-04-15c: Fully fold each parameter for call to .ACCESS_WITH_SIZE [PR119717]Qing Zhao1-2/+6
C_MAYBE_CONST_EXPR is a C FE operator that will be removed by c_fully_fold. In c_fully_fold, it assumes that operands of function calls have already been folded. However, when we build call to .ACCESS_WITH_SIZE, all its operands are not fully folded. therefore the C FE specific operator is passed to middle-end. In order to fix this issue, fully fold the parameters before building the call to .ACCESS_WITH_SIZE. PR c/119717 gcc/c/ChangeLog: * c-typeck.cc (build_access_with_size_for_counted_by): Fully fold the parameters for call to .ACCESS_WITH_SIZE. gcc/testsuite/ChangeLog: * gcc.dg/pr119717.c: New test.
2025-04-09Daily bump.GCC Administrator1-0/+9
2025-04-08c: fix checking for a tag for variably modified tagged types [PR119612]Martin Uecker3-16/+28
The checking assertion added for PR118765 did not take into account that add_decl_expr can change TYPE_NAME to a TYPE_DECL with no name for certain cases of variably modified types. This also implies that we might sometimes not reliably detect the absence of a tag when only considering TYPE_NAME. This patch introduces a new helper function c_type_tag to reliable compute the tag for a tagged types and uses it for code where the switch to C23 may cause regressions. PR c/119612 gcc/c/ChangeLog: * c-tree.h (c_type_tag): Add prototype. * c-typeck.cc (c_type_tag): New function. (tagged_types_tu_compatible_p, composite_type_internal): Use c_type_tag. * c-decl.cc (c_struct_hasher::hash, previous_tag): Use c_type_tag. gcc/testsuite/ChangeLog: * gcc.dg/gnu23-tag-6.c: New test. * gcc.dg/pr119612.c: New test.
2025-04-03Daily bump.GCC Administrator1-0/+16
2025-04-02c: Fix ICEs with -fsanitize=pointer-{subtract,compare} [PR119582]Jakub Jelinek1-4/+4
The following testcase ICEs because c_fully_fold isn't performed on the arguments of __sanitizer_ptr_{sub,cmp} builtins and so e.g. C_MAYBE_CONST_EXPR can leak into the gimplifier where it ICEs. 2025-04-02 Jakub Jelinek <jakub@redhat.com> PR c/119582 * c-typeck.cc (pointer_diff, build_binary_op): Call c_fully_fold on __sanitizer_ptr_sub or __sanitizer_ptr_cmp arguments. * gcc.dg/asan/pr119582.c: New test.
2025-04-02OpenMP: Require target and/or targetsync init modifier [PR118965]Sandra Loosemore1-31/+13
As noted in PR 118965, the initial interop implementation overlooked the requirement in the OpenMP spec that at least one of the "target" and "targetsync" modifiers is required in both the interop construct init clause and the declare variant append_args clause. Adding the check was fairly straightforward, but it broke about a gazillion existing test cases. In particular, things like "init (x, y)" which were previously accepted (and tested for being accepted) aren't supposed to be allowed by the spec, much less things like "init (target)" where target was previously interpreted as a variable name instead of a modifier. Since one of the effects of the change is that at least one modifier is always required, I found that deleting all the code that was trying to detect and handle the no-modifier case allowed for better diagnostics. gcc/c/ChangeLog PR middle-end/118965 * c-parser.cc (c_parser_omp_clause_init_modifiers): Adjust error message. (c_parser_omp_clause_init): Remove code for recognizing clauses without modifiers. Diagnose missing target/targetsync modifier. (c_finish_omp_declare_variant): Diagnose missing target/targetsync modifier. gcc/cp/ChangeLog PR middle-end/118965 * parser.cc (c_parser_omp_clause_init_modifiers): Adjust error message. (cp_parser_omp_clause_init): Remove code for recognizing clauses without modifiers. Diagnose missing target/targetsync modifier. (cp_finish_omp_declare_variant): Diagnose missing target/targetsync modifier. gcc/fortran/ChangeLog PR middle-end/118965 * openmp.cc (gfc_parser_omp_clause_init_modifiers): Fix some inconsistent code indentation. Remove code for recognizing clauses without modifiers. Diagnose prefer_type without a following paren. Adjust error message for an unrecognized modifier. Diagnose missing target/targetsync modifier. (gfc_match_omp_init): Fix more inconsistent code indentation. gcc/testsuite/ChangeLog PR middle-end/118965 * c-c++-common/gomp/append-args-1.c: Add target/targetsync modifiers so tests do what they were previously supposed to do. Adjust expected output. * c-c++-common/gomp/append-args-7.c: Likewise. * c-c++-common/gomp/append-args-8.c: Likewise. * c-c++-common/gomp/append-args-9.c: Likewise. * c-c++-common/gomp/interop-1.c: Likewise. * c-c++-common/gomp/interop-2.c: Likewise. * c-c++-common/gomp/interop-3.c: Likewise. * c-c++-common/gomp/interop-4.c: Likewise. * c-c++-common/gomp/pr118965-1.c: New. * c-c++-common/gomp/pr118965-2.c: New. * g++.dg/gomp/append-args-1.C: Add target/targetsync modifiers and adjust expected output. * g++.dg/gomp/append-args-2.C: Likewise. * g++.dg/gomp/append-args-6.C: Likewise. * g++.dg/gomp/append-args-7.C: Likewise. * g++.dg/gomp/append-args-8.C: Likewise. * g++.dg/gomp/interop-5.C: Likewise. * gfortran.dg/gomp/append_args-1.f90: Add target/targetsync modifiers and adjust expected output. * gfortran.dg/gomp/append_args-2.f90: Likewise. * gfortran.dg/gomp/append_args-3.f90: Likewise. * gfortran.dg/gomp/append_args-4.f90: Likewise. * gfortran.dg/gomp/interop-1.f90: Likewise. * gfortran.dg/gomp/interop-2.f90: Likewise. * gfortran.dg/gomp/interop-3.f90: Likewise. * gfortran.dg/gomp/interop-4.f90: Likewise. * gfortran.dg/gomp/pr118965-1.f90: New. * gfortran.dg/gomp/pr118965-2.f90: New.
2025-03-29Daily bump.GCC Administrator1-0/+5
2025-03-28srcextra fixesJakub Jelinek1-2/+1
Here is a patch which uses sed to fix up the copies of the generated files by flex/bison in the source directories (i.e. what we ship in release tarballs). In that case the generated files are in the same directory as the files they are generated from, so there should be no absolute or relative directories, just the filenames. Furthermore, c.srcextra was duplicating the work of gcc.srcextra, there is nothing C FE specific on gengtype-lex.l. 2025-03-28 Jakub Jelinek <jakub@redhat.com> gcc/ * Makefile.in (gcc.srcextra): Use sed to turn .../gcc/gengtype-lex.l in #line directives into just gengtype-lex.l. gcc/c/ * Make-lang.in (c.srcextra): Don't depend on anything and don't copy anything. gcc/cobol/ * Make-lang.in (cobol.srcextra): Use sed to turn .../gcc/cobol/*.{y,l,h,cc} and cobol/*.{y,l,h,cc} in #line directives into just *.{y,l,h,cc}.
2025-03-28Daily bump.GCC Administrator1-0/+8
2025-03-27c: Fix tagname confusion for typedef redefinitions [PR118765]Martin Uecker2-0/+7
When we redefine a typedef for a tagged type that has just been redefined, merge_decls may produce invalid TYPE_DECLS that are not consistent with what set_underlying_type produces. This is fixed by updating DECL_ORIGINAL_TYPE. PR c/118765 gcc/c/ChangeLog: * c-decl.cc (merge_decls): For TYPE_DECLS copy DECL_ORIGINAL_TYPE from the old declaration. * c-typeck.cc (tagged_types_tu_compatible_p): Add checking assertions. gcc/testsuite/ChangeLog: * gcc.dg/pr118765-2.c: New test. * gcc.dg/pr118765-3.c: New test. * gcc.dg/typedef-redecl3.c: New test.
2025-03-22Daily bump.GCC Administrator1-0/+6
2025-03-21OpenMP: 'interop' construct - add ME support + target-independent libgompPaul-Antoine Arras1-1/+5
This patch partially enables use of the OpenMP interop construct by adding middle end support, mostly in the omplower pass, and in the target-independent part of the libgomp runtime. It follows up on previous patches for C, C++ and Fortran front ends support. The full interop feature requires another patch to enable foreign runtime support in libgomp plugins. gcc/ChangeLog: * builtin-types.def (BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR): New. * gimple-low.cc (lower_stmt): Handle GIMPLE_OMP_INTEROP. * gimple-pretty-print.cc (dump_gimple_omp_interop): New function. (pp_gimple_stmt_1): Handle GIMPLE_OMP_INTEROP. * gimple.cc (gimple_build_omp_interop): New function. (gimple_copy): Handle GIMPLE_OMP_INTEROP. * gimple.def (GIMPLE_OMP_INTEROP): Define. * gimple.h (gimple_build_omp_interop): Declare. (gimple_omp_interop_clauses): New function. (gimple_omp_interop_clauses_ptr): Likewise. (gimple_omp_interop_set_clauses): Likewise. (gimple_return_set_retval): Handle GIMPLE_OMP_INTEROP. * gimplify.cc (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_INIT, OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY. (gimplify_omp_interop): New function. (gimplify_expr): Replace sorry with call to gimplify_omp_interop. * omp-builtins.def (BUILT_IN_GOMP_INTEROP): Define. * omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_INIT, OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY. (scan_omp_1_stmt): Handle GIMPLE_OMP_INTEROP. (lower_omp_interop_action_clauses): New function. (lower_omp_interop): Likewise. (lower_omp_1): Handle GIMPLE_OMP_INTEROP. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_destroy): Make addressable. (c_parser_omp_clause_init): Make addressable. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_clause_init): Make addressable. gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses): Make OMP_CLAUSE_DESTROY and OMP_CLAUSE_INIT addressable. * types.def (BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR): New. include/ChangeLog: * gomp-constants.h (GOMP_DEVICE_DEFAULT_OMP_61, GOMP_INTEROP_TARGET, GOMP_INTEROP_TARGETSYNC, GOMP_INTEROP_FLAG_NOWAIT): Define. libgomp/ChangeLog: * icv-device.c (omp_set_default_device): Check GOMP_DEVICE_DEFAULT_OMP_61. * libgomp-plugin.h (struct interop_obj_t): New. (enum gomp_interop_flag): New. (GOMP_OFFLOAD_interop): Declare. (GOMP_OFFLOAD_get_interop_int): Declare. (GOMP_OFFLOAD_get_interop_ptr): Declare. (GOMP_OFFLOAD_get_interop_str): Declare. (GOMP_OFFLOAD_get_interop_type_desc): Declare. * libgomp.h (_LIBGOMP_OMP_LOCK_DEFINED): Define. (struct gomp_device_descr): Add interop_func, get_interop_int_func, get_interop_ptr_func, get_interop_str_func, get_interop_type_desc_func. * libgomp.map: Add GOMP_interop. * libgomp_g.h (GOMP_interop): Declare. * target.c (resolve_device): Handle GOMP_DEVICE_DEFAULT_OMP_61. (omp_get_interop_int): Replace stub with actual implementation. (omp_get_interop_ptr): Likewise. (omp_get_interop_str): Likewise. (omp_get_interop_type_desc): Likewise. (struct interop_data_t): Define. (gomp_interop_internal): New function. (GOMP_interop): Likewise. (gomp_load_plugin_for_device): Load symbols for get_interop_int, get_interop_ptr, get_interop_str and get_interop_type_desc. * testsuite/libgomp.c-c++-common/interop-1.c: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/interop-1.c: Remove dg-prune-output "sorry". * c-c++-common/gomp/interop-2.c: Likewise. * c-c++-common/gomp/interop-3.c: Likewise. * c-c++-common/gomp/interop-4.c: Remove dg-message "not supported". * g++.dg/gomp/interop-5.C: Likewise. * gfortran.dg/gomp/interop-4.f90: Likewise. * c-c++-common/gomp/interop-5.c: New test. * gfortran.dg/gomp/interop-5.f90: New test. Co-authored-by: Tobias Burnus <tburnus@baylibre.com>
2025-03-20Daily bump.GCC Administrator1-0/+19
2025-03-19c: pedwarn on flexible array member initialization with {} for C23+ [PR119350]Jakub Jelinek1-6/+11
Even in C23/C2Y any initialization of flexible array member is still invalid, so we should emit a pedwarn on it. But we no longer do for initialization with {}. The reason is that for C17 and earlier, we already emitted a pedwarn on the {} initializer and so emitting another pedwarn on the flexible array member initialization would be diagnosing the same thing multiple times. In C23 we no longer pedwarn on {}, it is standard. The following patch arranges a pedwarning for that for C23+, so that at least one pedwarning is emitted. So that we don't "regress" from C17 to C23 on nested flexible array member initialization with no -pedantic/-pedantic-errors/-Wpedantic, the patch emits even the initialization of flexible array member in a nested context diagnostic as pedwarn in the {} case, after all, it doesn't cause much trouble, we just ignore it like before, it wouldn't initialize anything. 2025-03-19 Jakub Jelinek <jakub@redhat.com> PR c/119350 * c-typeck.cc (pop_init_level): Don't ignore empty brackets for flag_isoc23, still set constructor_type to NULL in that case but emit a pedwarn_init in that case. * gcc.dg/pr119350-1.c: New test. * gcc.dg/pr119350-2.c: New test. * gcc.dg/pr119350-3.c: New test.
2025-03-19c: Fix bug in typedef redefinitions of tagged types [PR118765]Martin Uecker1-2/+2
When we redefine a tagged type we incorrectly update TYPE_STUB_DECL of the previously defined type instead of the new one. Because TYPE_STUB_DECL is used when determining whether two such types are the same, this can cause valid typedef redefinitions to be rejected later. This is only a partial fix for PR118765. PR c/118765 gcc/c/ChangeLog: * c-decl.cc (finish_struct,finish_enum): Swap direction when copying TYPE_STRUB_DECL in redefinitions. gcc/testsuite/ChangeLog: * gcc.dg/pr118765.c: New test.
2025-03-19c: Fix ICE in error recovery when checking struct compatibility [PR118061]Martin Uecker1-0/+3
Return early when comparing two structures for compatibility and the type of a member is erroneous. PR c/118061 gcc/c/ChangeLog: * c-typeck.cc (tagged_types_tu_compatible_p): Handle errors in types of struct members. gcc/testsuite/ChangeLog: * gcc.dg/pr118061.c: New test.
2025-03-19Daily bump.GCC Administrator1-0/+16
2025-03-18c: Fix handling of [[gnu::musttail] return in if and else bodies [PR119311]Jakub Jelinek1-4/+4
The following new testcase FAILs with C (and succeeds with C++). c_parser_handle_musttail is used in c_parser_compound_statement_nostart where it is directly passed to c_parser_statement_after_labels, and in c_parser_all_labels where it is returned. Now, out of the 3 c_parser_all_labels callers, c_parser_statement passes it down to c_parser_statement_after_labels, but c_parser_if_body and c_parser_else_body don't, so if there are return statements with [[gnu::musttail]] or [[clang::musttail]] directly in if or else bodies rather than wrapped with {}s, we throw that information away. 2025-03-18 Jakub Jelinek <jakub@redhat.com> PR c/119311 * c-parser.cc (c_parser_if_body): Pass result of c_parser_all_labels as last argument to c_parser_statement_after_labels. (c_parser_else_body): Likewise. * c-c++-common/musttail14.c: Use * instead of \* in the regexps. * c-c++-common/musttail25.c: New test.
2025-03-18c, c++: Support musttail attribute even using __attribute__ form [PR116545]Jakub Jelinek1-2/+48
Apparently some programs in the wild use #if __has_attribute(musttail) __attribute__((musttail)) return foo (); #else return foo (); #endif clang supports musttail both as a standard attribute ([[clang::musttail]] which we also support for compatibility) and the above worked just fine with GCC 14 which had __has_attribute(musttail) 0. Now that it is 0, this doesn't compile anymore. So, either we need to ensure that __has_attribute(musttail) is 0 and just __has_c{,pp}_attribute({gnu,clang}::musttail) are non-zero, or IMHO better we just make it work in the attribute form, especially for C < C23 I can see why some projects would prefer that form. While [[gnu::musttail]] is rejected as an error in C11 etc. before GCC 15, rather than just handled as an unknown attribute. I view this as both a regression and compatibility issue. The patch handles it in similar spots to fallthrough/assume attributes inside of __attribute__ for C, and for C++ enables mixing of standard [[]] and GNU __attribute__(()) attributes at the start of statements in any order. While working on it, I've noticed we weren't diagnosing arguments to the clang::musttail attribute (fixed by the c-attribs.cc hunk) and newly on the __attribute__ form attribute (in that case the arguments aren't just skipped, they are always parsed and because we don't call decl_attributes etc., it wouldn't be diagnosed without a manual check). 2025-03-18 Jakub Jelinek <jakub@redhat.com> PR c/116545 gcc/ * doc/extend.texi (musttail statement attribute): Document that musttail GNU attribute can be used as well. gcc/c-family/ * c-attribs.cc (c_common_clang_attributes): Add musttail. gcc/c/ * c-parser.cc (c_parser_declaration_or_fndef): Parse __attribute__((musttail)) return. (c_parser_handle_musttail): Diagnose attribute arguments. (c_parser_statement_after_labels): Parse __attribute__((musttail)) return. gcc/cp/ * parser.cc (cp_parser_statement): Call cp_parser_attributes_opt rather than cp_parser_std_attribute_spec_seq. (cp_parser_jump_statement): Diagnose gnu::musttail attributes with no arguments. gcc/testsuite/ * c-c++-common/attr-fallthrough-2.c: Adjust expected diagnostics for C++. * c-c++-common/musttail15.c: New test. * c-c++-common/musttail16.c: New test. * c-c++-common/musttail17.c: New test. * c-c++-common/musttail18.c: New test. * c-c++-common/musttail19.c: New test. * c-c++-common/musttail20.c: New test. * c-c++-common/musttail21.c: New test. * c-c++-common/musttail22.c: New test. * c-c++-common/musttail23.c: New test. * c-c++-common/musttail24.c: New test. * g++.dg/musttail7.C: New test. * g++.dg/musttail8.C: New test. * g++.dg/musttail12.C: New test. * g++.dg/musttail13.C: New test. * g++.dg/musttail14.C: New test. * g++.dg/ext/pr116545.C: New test.
2025-03-12Daily bump.GCC Administrator1-0/+17
2025-03-11c: Don't emit -Wunterminated-string-initialization warning for ↵Jakub Jelinek1-1/+5
multi-dimensional nonstring array initializers [PR117178] My/Kees' earlier patches adjusted -Wunterminated-string-initialization warning so that it doesn't warn about initializers of nonstring decls and that nonstring attribute is allowed on multi-dimensional arrays. Unfortunately as this testcase shows, we still warn about initializers of multi-dimensional array nonstring decls. The problem is that in that case field passed to output_init_element is actually INTEGER_CST, index into the array. For RECORD_OR_UNION_TYPE_P (constructor_type) field is a FIELD_DECL which we want to use, but otherwise (in arrays) IMHO we want to use constructor_fields (which is the innermost FIELD_DECL whose part is being initialized), or - if that is NULL - constructor_decl, the whole decl being initialized with multi-dimensional array type. 2025-03-11 Jakub Jelinek <jakub@redhat.com> PR c/117178 * c-typeck.cc (output_init_element): Pass field to digest_init only for record/union types, otherwise pass constructor_fields if non-NULL and constructor_decl if constructor_fields is NULL. * gcc.dg/Wunterminated-string-initialization-2.c: New test.
2025-03-11OpenMP/C: Store location in cp_parser_omp_var_list for kind=0 [PR118579]Sandra Loosemore1-22/+14
This patch is the C equivalent of commit r15-6512-gcf94ba812ca496 for C++, to improve the location information for individual items in an OpenMP variable list. gcc/c/ChangeLog PR c/118579 * c-parser.cc (c_parser_omp_variable_list): Capture location information when KIND is OMP_CLAUSE_ERROR. (c_parser_oacc_data_clause_deviceptr): Use the improved location for diagnostics, and remove the FIXME. (c_finish_omp_declare_variant): Likewise. (c_parser_omp_threadprivate): Likewise. gcc/testsuite/ChangeLog PR c/118579 * c-c++-common/gomp/pr118579.c: New testcase.
2025-03-08Daily bump.GCC Administrator1-0/+21
2025-03-07c: do not warn about truncating NUL char when initializing nonstring arrays ↵Jakub Jelinek1-25/+37
[PR117178] When initializing a nonstring char array when compiled with -Wunterminated-string-initialization the warning trips even when truncating the trailing NUL character from the string constant. Only warn about this when running under -Wc++-compat since under C++ we should not initialize nonstrings from C strings. This patch separates the -Wunterminated-string-initialization and -Wc++-compat warnings, they are now independent option, the former implied by -Wextra, the latter not implied by anything. If -Wc++-compat is in effect, it takes precedence over -Wunterminated-string-initialization and warns regardless of nonstring attribute, otherwise if -Wunterminated-string-initialization is enabled, it warns only if there isn't nonstring attribute. In all cases, the warnings and also pedwarn_init for even larger sizes now provide details on the lengths. 2025-03-07 Kees Cook <kees@kernel.org> Jakub Jelinek <jakub@redhat.com> PR c/117178 gcc/ * doc/invoke.texi (Wunterminated-string-initialization): Document the new interaction between this warning and -Wc++-compat and that initialization of decls with nonstring attribute aren't warned about. gcc/c-family/ * c.opt (Wunterminated-string-initialization): Don't depend on -Wc++-compat. gcc/c/ * c-typeck.cc (digest_init): Add DECL argument. Adjust wording of pedwarn_init for too long strings and provide details on the lengths, for string literals where just the trailing NULL doesn't fit warn for warn_cxx_compat with OPT_Wc___compat, wording which mentions "for C++" and provides details on lengths, otherwise for warn_unterminated_string_initialization adjust the warning, provide details on lengths and don't warn if get_attr_nonstring_decl (decl). (build_c_cast, store_init_value, output_init_element): Adjust digest_init callers. gcc/testsuite/ * gcc.dg/Wunterminated-string-initialization.c: Add additional test coverage. * gcc.dg/Wcxx-compat-14.c: Check in dg-warning for "for C++" part of the diagnostics. * gcc.dg/Wcxx-compat-23.c: New test. * gcc.dg/Wcxx-compat-24.c: New test. Signed-off-by: Kees Cook <kees@kernel.org>
2025-03-07c: Fix warning after an error on a return statment [PR60440]Andrew Pinski1-1/+6
Like r5-6912-g3dbb84276aca10 but this is for the C front-end. Basically we have an error on a return statement, we just return error_mark_node and then the warning happens as there is no return statement. Anyways instead mark the current function for supression of the warning instead. PR c/60440 gcc/c/ChangeLog: * c-typeck.cc (c_finish_return): Mark the current function for supression of the -Wreturn-type if there was an error on the return statement. gcc/testsuite/ChangeLog: * gcc.dg/Wreturn-mismatch-2.c: Change dg-warning for the last -Wreturn-type to dg-bogus. * gcc.dg/pr60440-1.c: New test. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>