aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.cc
AgeCommit message (Collapse)AuthorFilesLines
2025-06-05OpenMP: Handle more cases in user/condition selectorSandra Loosemore1-4/+17
Tobias had noted that the C front end was not treating C23 constexprs as constant in the user/condition selector property, which led to missed opportunities to resolve metadirectives at parse time. Additionally neither C nor C++ was permitting the expression to have pointer or floating-point type -- the former being a common idiom in other C/C++ conditional expressions. By using the existing front-end hooks for the implicit conversion to bool in conditional expressions, we also get free support for using a C++ class object that has a bool conversion operator in the user/condition selector. gcc/c/ChangeLog * c-parser.cc (c_parser_omp_context_selector): Call convert_lvalue_to_rvalue and c_objc_common_truthvalue_conversion on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR. gcc/cp/ChangeLog * cp-tree.h (maybe_convert_cond): Declare. * parser.cc (cp_parser_omp_context_selector): Call maybe_convert_cond and fold_build_cleanup_point_expr on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR. * pt.cc (tsubst_omp_context_selector): Likewise. * semantics.cc (maybe_convert_cond): Remove static declaration. gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-2.c: Update expected output. * c-c++-common/gomp/metadirective-condition-constexpr.c: New. * c-c++-common/gomp/metadirective-condition.c: New. * c-c++-common/gomp/metadirective-error-recovery.c: Update expected output. * g++.dg/gomp/metadirective-condition-class.C: New. * g++.dg/gomp/metadirective-condition-template.C: New. (cherry picked from commit 08c299a410b9314957e48a87f5bf50a4c034b744)
2025-06-02Merge branch 'releases/gcc-15' into devel/omp/gcc-15Tobias Burnus1-11/+5
Merge up to r15-9755-g21e0a742e7b70d (2nd July 2025)
2025-05-30OpenMP: Fix ICE and other issues in C/C++ metadirective error recovery.Sandra Loosemore1-8/+1
The new testcase included in this patch used to ICE in gcc after diagnosing the first error, and in g++ it only diagnosed the error in the first metadirective, ignoring the second one. The solution is to make error recovery in the C front end more like that in the C++ front end, and remove the code in both front ends that previously tried to skip all the way over the following statement (instead of just to the end of the metadirective pragma) after an error. gcc/c/ChangeLog * c-parser.cc (c_parser_skip_to_closing_brace): New, copied from the equivalent function in the C++ front end. (c_parser_skip_to_end_of_block_or_statement): Pass false to the error flag. (c_parser_omp_context_selector): Immediately return error_mark_node after giving an error that the integer trait property is invalid, similarly to C++ front end. (c_parser_omp_context_selector_specification): Likewise handle error return from c_parser_omp_context_selector similarly to C++. (c_parser_omp_metadirective): Do not call c_parser_skip_to_end_of_block_or_statement after an error. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_metadirective): Do not call cp_parser_skip_to_end_of_block_or_statement after an error. gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-2.c: Adjust patterns now that C and C++ now behave similarly. * c-c++-common/gomp/metadirective-error-recovery.c: New. (cherry picked from commit 33b65e4d1c83808b54cd6b3fc97ebacc522b125d)
2025-05-30OpenMP: Fix ICE in metadirective recovery after error [PR120180]Sandra Loosemore1-3/+4
It's not clear whether a metadirective in a loop nest is supposed to be valid, but GCC certainly shouldn't be ICE'ing after diagnosing it as an error. gcc/c/ChangeLog PR c/120180 * c-parser.cc (c_parser_omp_metadirective): Only consume the token if it is the expected close paren. gcc/cp/ChangeLog PR c/120180 * parser.cc (cp_parser_omp_metadirective): Only consume the token if it is the expected close paren. gcc/testsuite/ChangeLog PR c/120180 * c-c++-common/gomp/pr120180.c: New. (cherry picked from commit 65e0ed2310a1b0d1a3255583bbfb8a8d86c5aea5)
2025-05-15OpenMP: need_device_ptr and need_device_addr support for adjust_argsSandra Loosemore1-3/+4
This patch adds support for the "need_device_addr" modifier to the "adjust args" clause for the "declare variant" directive, and extends/re-works the support for "need_device_ptr" as well. This patch builds on waffl3x's recently posted patch, "OpenMP: C/C++ adjust-args numeric ranges", here. https://gcc.gnu.org/pipermail/gcc-patches/2025-April/681806.html In C++, "need_device_addr" supports mapping reference arguments to device pointers. In Fortran, it similarly supports arguments passed by reference, the default for the language, in contrast to "need_device_ptr" which is used to map arguments of c_ptr type. The C++ support is straightforward, but Fortran has some additional wrinkles involving arrays passed by descriptor (a new descriptor must be constructed with a pointer to the array data which is the only part mapped to the device), plus special cases for passing optional arguments and a whole array instead of a reference to its first element. gcc/cp/ChangeLog * parser.cc (cp_finish_omp_declare_variant): Adjust error messages. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Disallow polymorphic and optional arguments with need_device_addr for now, but don't reject need_device_addr entirely. gcc/ChangeLog * gimplify.cc (modify_call_for_omp_dispatch): Rework logic for need_device_ptr and need_device_addr adjustments. gcc/testsuite/ChangeLog * c-c++-common/gomp/adjust-args-10.c: Ignore the new sorry since the lack of proper diagnostic is already xfail'ed. * g++.dg/gomp/adjust-args-1.C: Adjust output patterns. * g++.dg/gomp/adjust-args-17.C: New. * gcc.dg/gomp/adjust-args-3.c: New. * gfortran.dg/gomp/adjust-args-14.f90: Don't expect this to fail now. libgomp/ChangeLog * libgomp.texi: Mark need_device_addr as supported. * testsuite/libgomp.c++/need-device-ptr.C: New. * testsuite/libgomp.c-c++-common/dispatch-3.c: New. * testsuite/libgomp.fortran/adjust-args-array-descriptor.f90: New. * testsuite/libgomp.fortran/need-device-ptr.f90: New. Co-Authored-By: Tobias Burnus <tburnus@baylibre.com>
2025-05-15OpenMP: C/C++ adjust-args numeric rangeswaffl3x1-74/+472
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>
2025-05-15openmp: 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>
2025-05-15openmp: Add macros for iterator element accessKwok Cheung Yeung1-8/+8
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.
2025-05-15openmp: Add support for iterators in 'target update' clauses (C/C++)Kwok Cheung Yeung1-6/+50
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.
2025-05-15openmp: Add support for iterators in map clauses (C/C++)Kwok Cheung Yeung1-5/+52
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>
2025-05-15OpenACC 2.7: Implement reductions for arrays and recordsChung-Lin Tang1-2/+11
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.
2025-05-15OpenMP: C++ front end support for "begin declare variant"Sandra Loosemore1-33/+511
This patch implements C++ support for the "begin declare variant" construct. The OpenMP specification is hazy on interaction of this feature with C++ language features. Variant functions in classes are supported but must be defined as members in the class definition, using an unqualified name for the base function which also must be present in that class. Similarly variant functions in a namespace can only be defined in that namespace using an unqualified name for a base function already declared in that namespace. Variants for template functions or inside template classes seem to (mostly) work. gcc/cp/ChangeLog * cp-tree.h (struct cp_omp_declare_variant_attr): New. (struct saved_scope): Add omp_declare_variant_attribute field. * decl.cc (omp_declare_variant_finalize_one): Add logic to inject "this" parameter for method calls. * parser.cc (cp_parser_skip_to_pragma_omp_end_declare_variant): New. (omp_start_variant_function): New. (omp_finish_variant_function): New. (cp_parser_init_declarator): Handle variant functions. (cp_parser_class_specifier): Handle deferred lookup of base functions when the entire class has been seen. (cp_parser_member_declaration): Handle variant functions. (cp_finish_omp_declare_variant): Merge context selectors if in a "begin declare variant" block. (cp_parser_omp_begin): Match "omp begin declare variant". Adjust error messages. (cp_parser_omp_end): Match "omp end declare variant". * parser.h (struct cp_parser): Add omp_unregistered_variants field. * semantics.cc (finish_translation_unit): Detect unmatched "omp begin declare variant". gcc/testsuite/ChangeLog * g++.dg/gomp/delim-declare-variant-1.C: New. * g++.dg/gomp/delim-declare-variant-2.C: New. * g++.dg/gomp/delim-declare-variant-3.C: New. * g++.dg/gomp/delim-declare-variant-4.C: New. * g++.dg/gomp/delim-declare-variant-5.C: New. * g++.dg/gomp/delim-declare-variant-6.C: New. * g++.dg/gomp/delim-declare-variant-7.C: New. * g++.dg/gomp/delim-declare-variant-40.C: New. * g++.dg/gomp/delim-declare-variant-41.C: New. * g++.dg/gomp/delim-declare-variant-50.C: New. * g++.dg/gomp/delim-declare-variant-51.C: New. * g++.dg/gomp/delim-declare-variant-52.C: New. * g++.dg/gomp/delim-declare-variant-70.C: New. * g++.dg/gomp/delim-declare-variant-71.C: New. libgomp/ * testsuite/libgomp.c++/delim-declare-variant-1.C: New. * testsuite/libgomp.c++/delim-declare-variant-2.C: New. * testsuite/libgomp.c++/delim-declare-variant-7.C: New. Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: waffl3x <waffl3x@baylibre.com>
2025-05-15OpenMP: Add C++ support for 'omp allocate'waffl3x1-53/+326
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>
2025-05-15OpenMP: Enable 'declare mapper' mappers for 'target update' directivesJulian Brown1-12/+148
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>
2025-05-15OpenMP: Support strided and shaped-array updates for C++Julian Brown1-25/+278
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.
2025-05-15OpenMP: Expand "declare mapper" mappers for target {enter,exit,} data directivesJulian Brown1-3/+12
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.
2025-05-15OpenMP: C++ "declare mapper" supportJulian Brown1-11/+277
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 <julian@codesourcery.com> gcc/c-family/ * c-common.h (c_omp_region_type): Add C_ORT_DECLARE_MAPPER and C_ORT_OMP_DECLARE_MAPPER codes. (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): Add prototype. (cp_check_omp_declare_mapper): Add prototype. (omp_instantiate_mappers): Add prototype. (cxx_omp_finish_mapper_clauses): Add prototype. (cxx_omp_mapper_lookup): Add prototype. (cxx_omp_extract_mapper_directive): Add prototype. (cxx_omp_map_array_section): Add prototype. * 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_MAP_ARRAY_SECTION hooks. * omp-general.h (omp_name_type<T>): Add templatized struct, hash type traits (for omp_name_type<tree> specialization). (omp_mapper_list<T>): Add struct. * tree-core.h (omp_clause_code): Add OMP_CLAUSE__MAPPER_BINDING_. * tree-pretty-print.cc (dump_omp_clause): Support GOMP_MAP_UNSET, GOMP_MAP_PUSH_MAPPER_NAME, GOMP_MAP_POP_MAPPER_NAME artificial mapping clauses. Support OMP_CLAUSE__MAPPER_BINDING_ and OMP_DECLARE_MAPPER. * tree.cc (omp_clause_num_ops, omp_clause_code_name): Add OMP_CLAUSE__MAPPER_BINDING_. * tree.def (OMP_DECLARE_MAPPER): New tree code. * tree.h (OMP_DECLARE_MAPPER_ID, OMP_DECLARE_MAPPER_DECL, OMP_DECLARE_MAPPER_CLAUSES): New defines. (OMP_CLAUSE__MAPPER_BINDING__ID, OMP_CLAUSE__MAPPER_BINDING__DECL, OMP_CLAUSE__MAPPER_BINDING__MAPPER): New defines. include/ * gomp-constants.h (gomp_map_kind): Add GOMP_MAP_UNSET, GOMP_MAP_PUSH_MAPPER_NAME, GOMP_MAP_POP_MAPPER_NAME artificial mapping clause types. gcc/testsuite/ * c-c++-common/gomp/map-6.c: Update error scan output. * c-c++-common/gomp/declare-mapper-3.c: New test (only enabled for C++ for now). * 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: Likewise. * g++.dg/gomp/declare-mapper-1.C: New test. * g++.dg/gomp/declare-mapper-2.C: New test. libgomp/ * testsuite/libgomp.c++/declare-mapper-1.C: New test. * testsuite/libgomp.c++/declare-mapper-2.C: New test. * testsuite/libgomp.c++/declare-mapper-3.C: New test. * testsuite/libgomp.c++/declare-mapper-4.C: New test. * testsuite/libgomp.c++/declare-mapper-5.C: New test. * testsuite/libgomp.c++/declare-mapper-6.C: New test. * testsuite/libgomp.c++/declare-mapper-7.C: New test. * testsuite/libgomp.c++/declare-mapper-8.C: New test. * testsuite/libgomp.c-c++-common/declare-mapper-9.c: New test (only enabled for C++ for now). * 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.
2025-05-15OpenMP: Add uses_allocators supportTobias Burnus1-1/+236
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.
2025-05-15Various OpenACC reduction enhancements - FE changesJulian Brown1-14/+17
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>
2025-04-16c++: ill-formed constexpr function [PR113360]Jason Merrill1-0/+5
If we already gave an error while parsing a function, we don't also need to try to explain what's wrong with it when we later try to use it in a constant-expression. In the new testcase explain_invalid_constexpr_fn couldn't find anything still in the function to complain about, so it said because: followed by nothing. We still try to constant-evaluate it to reduce error cascades, but we shouldn't complain if it doesn't work very well. This flag is similar to CLASSTYPE_ERRONEOUS that I added a while back. PR c++/113360 gcc/cp/ChangeLog: * cp-tree.h (struct language_function): Add erroneous bit. * constexpr.cc (explain_invalid_constexpr_fn): Return if set. (cxx_eval_call_expression): Quiet if set. * parser.cc (cp_parser_function_definition_after_declarator) * pt.cc (instantiate_body): Set it. gcc/testsuite/ChangeLog: * g++.dg/cpp23/constexpr-nonlit18.C: Remove redundant message. * g++.dg/cpp1y/constexpr-diag2.C: New test. * g++.dg/cpp1y/pr63996.C: Adjust expected errors. * g++.dg/template/explicit-args6.C: Likewise. * g++.dg/cpp0x/constexpr-ice21.C: Likewise.
2025-04-04c++: lambda in requires outside template [PR99546]Jason Merrill1-11/+24
Since r10-7441 we set processing_template_decl in a requires-expression so that we can use tsubst_expr to evaluate the requirements, but that confuses lambdas terribly; begin_lambda_type silently returns error_mark_node and we continue into other failures. This patch clears processing_template_decl again while we're defining the closure and op() function, so it only remains set while parsing the introducer (i.e. any init-captures) and building the resulting object. This properly avoids trying to create another lambda in tsubst_lambda_expr. PR c++/99546 PR c++/113925 PR c++/106976 PR c++/109961 PR c++/117336 gcc/cp/ChangeLog: * lambda.cc (build_lambda_object): Handle fake requires-expr processing_template_decl. * parser.cc (cp_parser_lambda_expression): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-requires2.C: New test. * g++.dg/cpp2a/lambda-requires3.C: New test. * g++.dg/cpp2a/lambda-requires4.C: New test. * g++.dg/cpp2a/lambda-requires5.C: New test.
2025-04-02OpenMP: Require target and/or targetsync init modifier [PR118965]Sandra Loosemore1-31/+14
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-04-02c++: Rename -fmodules-ts to -fmodules in diagnosticsNathaniel Shead1-3/+3
This replaces some usages of the old -fmodules-ts flag with the new -fmodules flag made in r15-5112-gd9c3c3c85665b2. gcc/cp/ChangeLog: * parser.cc (cp_parser_diagnose_invalid_type_name): Replace fmodules-ts with fmodules. (cp_parser_template_declaration): Likewise. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-03-25c++: lambda, default argument, unevaluated contextyxj-github-4371-0/+3
This patch would like to avoid the ICE when template lambdas call with default parameters in unevaluated context. The bug is the same as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119385. For example: 1 | template <class T> 2 | void foo(T x) { 3 | sizeof []<int=0>(T=x) { return 0; }(); 4 | } 5 | 6 | void test { 7 | foo(0); 8 | } when compile with -fsyntax-only -std=c++20, it will have ICE similar to test.cc: In instantiation of 'void foo(T) [with T = int]': test.cc:7:6: required from here 6 | foo(0); | ~~~^~~ test.cc:3:38: internal compiler error: in tsubst_expr, at cp/pt.cc:21919 2 | sizeof []<int=0>(T=x) { return 0; }(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ And if without the template code `<int=0>`, the code will pass compile, it's wrong. When parsing lambda, the sizeof will affect the lambda internal unevaluated operand being handled. So consider save/restore cp_unevaluated_operand. gcc/cp/ChangeLog: * parser.cc (cp_parser_lambda_expression): Use cp_evaluated. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-uneval25.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-03-21OpenMP: 'interop' construct - add ME support + target-independent libgompPaul-Antoine Arras1-0/+1
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-18c, c++: Support musttail attribute even using __attribute__ form [PR116545]Jakub Jelinek1-2/+7
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-08inline-asm: Improve documentation of "asm constexpr".Sandra Loosemore1-4/+4
While working on an adjacent documentation fix, I noticed that the documentation for the gnu++11 "asm constexpr" feature was very confusing, in some cases being attached to parts of the asm syntax that are not otherwise required to be string literals, and missing from other parts of the syntax that are. I've checked what the C++ parser actually does and fixed the documentation to match, also improving it to use correct markup and to be more explicit and less implementor-speaky. gcc/cp/ChangeLog * parser.cc (cp_parser_asm_definition): Make comment more explicit. (cp_parser_asm_operand_list): Likewise. Also correct the comment block at the top of the function to reflect reality. gcc/ChangeLog * doc/extend.texi (Basic Asm): Document that AssemblerInstructions can be an asm constexpr. (Extended Asm): Move the notes about asm constexprs for AssemblerTemplate and Clobbers to the corresponding subsections. Remove the notes for OutputOperands and InputOperands and reword misleading descriptions of the list item syntax. Note that constraint strings can be asm constexprs. (Asm constexprs): Use "title case" for subsection name. Be explicit about what parts of the asm syntax this applies to and that the parentheses are required. Correct markup and terminology.
2025-03-06Fix comment typosSimon Martin1-1/+1
While investigating PR c++/99538 I noticed two comment typos: "delared" and "paramter". The first has a single occurrence, but the second a few more. This patch fixes all of them. gcc/ChangeLog: * config/i386/x86-tune-sched.cc (ix86_fuse_mov_alu_p): Fix comment typo, paramter -> parameter. * config/lm32/lm32.cc (lm32_std_gimplify_va_arg_expr): Likewise. gcc/cp/ChangeLog: * cp-tree.h (processing_contract_condition): Fix comment typo, paramter -> parameter. * parser.cc (cp_parser_requires_expression): Fix comment typo, delared -> declared. gcc/rust/ChangeLog: * rust-diagnostics.h (RUST_ATTRIBUTE_GCC_DIAG): Fix comment typo, paramter -> parameter. gcc/testsuite/ChangeLog: * gcc.target/powerpc/ppc64-abi-1.c: Fix comment typos, paramter -> parameter. * gcc.target/powerpc/ppc64-abi-2.c: Likewise.
2025-03-06c++: Update TYPE_FIELDS of variant types if ↵Jakub Jelinek1-30/+33
cp_parser_late_parsing_default_args etc. modify it [PR98533] The following testcases ICE during type verification, because TYPE_FIELDS of e.g. S RECORD_TYPE in pr119123.C is different from TYPE_FIELDS of const S. Various decls are added to S's TYPE_FIELDS first, then finish_struct indirectly calls fixup_type_variants to sync the variant copies. But later on cp_parser_class_specifier calls cp_parser_late_parsing_default_args and that apparently adds a lambda type (from default argument) to TYPE_FIELDS of S. Dunno if that is right or not, assuming it is right, the following patch fixes it by updating TYPE_FIELDS of variant types if there were any changes in the various functions cp_parser_class_specifier defers and calls on the outermost enclosing class. There was quite a lot of code repetition already before, so the patch uses a lambda to avoid the repetitions. To my surprise, in some of the contract testcases ( g++.dg/contracts/contracts-friend1.C g++.dg/contracts/contracts-nested-class1.C g++.dg/contracts/contracts-nested-class2.C g++.dg/contracts/contracts-redecl7.C g++.dg/contracts/contracts-redecl8.C ) it is actually setting class_type and pushing TRANSLATION_UNIT_DECL rather than some class types in some cases. Or should the lambda pushing into the containing class be somehow avoided? 2025-03-06 Jakub Jelinek <jakub@redhat.com> PR c++/98533 PR c++/119123 * parser.cc (cp_parser_class_specifier): Update TYPE_FIELDS of variant types in case cp_parser_late_parsing_default_args etc. change TYPE_FIELDS on the main variant. Add switch_to_class lambda and use it to simplify repeated class switching code. * g++.dg/cpp0x/pr98533.C: New test. * g++.dg/cpp0x/pr119123.C: New test.
2025-02-27c++: too many errors with sneaky template [PR118516]Marek Polacek1-1/+0
Since C++20 P0846, a name followed by a < can be treated as a template-name even though name lookup did not find a template-name. That happens in this test with "i < foo ()": for (int id = 0; i < foo(); ++id); and results in a raft of errors about non-constant foo(). The problem is that the require_potential_constant_expression call in cp_parser_template_argument emits errors even when we're parsing tentatively. So we repeat the error when we're trying to parse as a nested-name-specifier, type-name, etc. Guarding the call with !cp_parser_uncommitted_to_tentative_parse_p would mean that require_potential_constant_expression never gets called. But we don't need the call at all as far as I can tell. Stuff like template<int N> struct S { }; int foo () { return 4; } void g () { S<foo()> s; } gets diagnosed in convert_nontype_argument. In fact, with this patch, we only emit "call to non-constexpr function" once. (That is, in C++17 only; C++14 uses a different path.) PR c++/118516 gcc/cp/ChangeLog: * parser.cc (cp_parser_template_argument): Don't call require_potential_constant_expression. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/fn-template11.C: * g++.dg/template/fn-template1.C: New test. * g++.dg/template/fn-template2.C: New test.
2025-02-22OpenMP: Silence uninitialized variable warning in C++ front end.Sandra Loosemore1-1/+1
There's no actual problem with the code here, just a false-positive warning emitted by some older GCC versions. gcc/cp/ChangeLog * parser.cc (cp_finish_omp_declare_variant): Initialize append_args_last.
2025-02-14c++: Fix mangling of lambas in static member template initializers [PR107741]Nathaniel Shead1-12/+34
My fix for this issue in r15-7147 turns out to not be quite sufficient; static member templates apparently go down a different code path and need their own handling. PR c++/107741 gcc/cp/ChangeLog: * cp-tree.h (is_static_data_member_initialized_in_class): Declare new predicate. * decl2.cc (start_initialized_static_member): Push the TEMPLATE_DECL when appropriate. (is_static_data_member_initialized_in_class): New predicate. (finish_initialized_static_member): Use it. * lambda.cc (record_lambda_scope): Likewise. * parser.cc (cp_parser_init_declarator): Start the member decl early for static members so that lambda scope is set. (cp_parser_template_declaration_after_parameters): Don't register in-class initialized static members here. gcc/testsuite/ChangeLog: * g++.dg/abi/lambda-ctx2-19.C: Add tests for template members. * g++.dg/abi/lambda-ctx2-19vs20.C: Likewise. * g++.dg/abi/lambda-ctx2-20.C: Likewise. * g++.dg/abi/lambda-ctx2.h: Likewise. * g++.dg/cpp0x/static-member-init-1.C: Likewise. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
2025-02-11c++: change implementation of -frange-for-ext-temps [PR118574]Jason Merrill1-20/+3
The implementation in r15-3840 used a novel technique of wrapping the entire range-for loop in a CLEANUP_POINT_EXPR, which confused the coroutines transformation. Instead let's use the existing extend_ref_init_temps mechanism. This does not revert all of r15-3840, only the parts that change how CLEANUP_POINT_EXPRs are applied to range-for declarations. PR c++/118574 PR c++/107637 gcc/cp/ChangeLog: * call.cc (struct extend_temps_data): New. (extend_temps_r, extend_all_temps): New. (set_up_extended_ref_temp): Handle tree walk case. (extend_ref_init_temps): Cal extend_all_temps. * decl.cc (initialize_local_var): Revert ext-temps change. * parser.cc (cp_convert_range_for): Likewise. (cp_parser_omp_loop_nest): Likewise. * pt.cc (tsubst_stmt): Likewise. * semantics.cc (finish_for_stmt): Likewise. gcc/testsuite/ChangeLog: * g++.dg/coroutines/range-for1.C: New test.
2025-02-11OpenMP: Pass a 3-way flag to omp_check_context_selector instead of a bool.Sandra Loosemore1-2/+4
The OpenMP "begin declare variant" directive has slightly different requirements for context selectors than regular "declare variant", so something more than a bool is required to tell the error-checking routine what to check. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Change metadirective_p argument to a 3-way flag. Add extra check for OMP_CTX_BEGIN_DECLARE_VARIANT. * omp-general.h (enum omp_ctx_directive): New. (omp_check_context_selector): Adjust declaration. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Update call to omp_check_context_selector. (c_parser_omp_metadirective): Likewise. gcc/cp/ChangeLog * parser.cc (cp_finish_omp_declare_variant): Update call to omp_check_context_selector. (cp_parser_omp_metadirective): Likewise. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Update call to omp_check_context_selector. (gfc_trans_omp_metadirective): Likewise.
2025-02-07c++: Fix up name independent decl in structured binding handling in range ↵Jakub Jelinek1-0/+10
for [PR115586] cp_parser_range_for temporarily reverts IDENTIFIER_BINDING changes to hide the decls from the structured bindings from lookup during parsing of the expression after : If there are 2 or more name independent decls, we undo IDENTIFIER_BINDING for the same name multiple times, even when just one has been added (with a TREE_LIST inside of it as decl). The following patch fixes it by handling the _ name at most once, the later loop will DTRT then and just reinstall the temporarily hidden binding with the TREE_LIST in there. 2025-02-07 Jakub Jelinek <jakub@redhat.com> PR c++/115586 * parser.cc (cp_parser_range_for): For name independent decls in structured bindings, only push the name/binding once per structured binding. * g++.dg/cpp26/name-independent-decl9.C: New test. * g++.dg/cpp26/name-independent-decl10.C: New test.
2025-02-04c++: auto in trailing-return-type in parameter [PR117778]Marek Polacek1-9/+30
This PR describes a few issues, both ICE and rejects-valid, but ultimately the problem is that we don't properly synthesize the second auto in: int g (auto fp() -> auto) { return fp (); } since r12-5860, which disabled auto_is_implicit_function_template_parm_p in cp_parser_parameter_declaration after parsing the decl-specifier-seq. If there is no trailing auto, there is no problem. So we have to make sure auto_is_implicit_function_template_parm_p is properly set when parsing the trailing auto. A complication is that one can write: auto f (auto fp(auto fp2() -> auto) -> auto) -> auto; ~~~~~~~ where only the underlined auto should be synthesized. So when we parse a parameter-declaration-clause inside another parameter-declaration-clause, we should not enable the flag. We have no flags to keep track of such nesting, but I think I can walk current_binding_level to see if we find ourselves in such an unlikely scenario. PR c++/117778 gcc/cp/ChangeLog: * parser.cc (cp_parser_late_return_type_opt): Maybe override auto_is_implicit_function_template_parm_p. (cp_parser_parameter_declaration): Move a make_temp_override below. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-117778.C: New test. * g++.dg/cpp2a/abbrev-fn2.C: New test. * g++.dg/cpp2a/abbrev-fn3.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-02-04c++: bogus -Wvexing-parse with trailing-return-type [PR118718]Marek Polacek1-0/+4
This warning should not warn for auto f1 () -> auto; because that cannot be confused with initializing a variable. PR c++/118718 gcc/cp/ChangeLog: * parser.cc (warn_about_ambiguous_parse): Don't warn when a trailing return type is present. gcc/testsuite/ChangeLog: * g++.dg/warn/Wvexing-parse10.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-01-30OpenMP: append_args clause fixes + Fortran supportTobias Burnus1-8/+19
This fixes a large number of smaller and larger issues with the append_args clause to 'declare variant' and adds Fortran support for it; it also contains a larger number of testcases. In particular, for Fortran, it also handles passing allocatable, pointer, optional arguments to an interop dummy argument with or without value attribute. And it changes the internal representation such that dumping the tree does not lead to an ICE. gcc/c/ChangeLog: * c-parser.cc (c_finish_omp_declare_variant): Modify how append_args is saved internally. gcc/cp/ChangeLog: * parser.cc (cp_finish_omp_declare_variant): Modify how append_args is saved internally. * pt.cc (tsubst_attribute): Likewise. (tsubst_omp_clauses): Remove C_ORT_OMP_DECLARE_SIMD from interop handling as no longer called for it. * decl.cc (omp_declare_variant_finalize_one): Update append_args changes; fixes for ADL input. gcc/fortran/ChangeLog: * gfortran.h (gfc_omp_declare_variant): Add append_args_list. * openmp.cc (gfc_parser_omp_clause_init_modifiers): New; splitt of from ... (gfc_match_omp_init): ... here; call it. (gfc_match_omp_declare_variant): Update to handle append_args clause; some syntax handling fixes. * trans-openmp.cc (gfc_trans_omp_declare_variant): Handle append_args clause; add some diagnostic. gcc/ChangeLog: * gimplify.cc (gimplify_call_expr): For OpenMP's append_args clause processed by 'omp dispatch', update for internal-representation changes; fix handling of hidden arguments, add some comments and handle Fortran's value dummy and optional/pointer/allocatable actual args. libgomp/ChangeLog: * libgomp.texi (Impl. Status): Update for accumpulated changes related to 'dispatch' and interop. gcc/testsuite/ChangeLog: * c-c++-common/gomp/append-args-1.c: Update dg-*. * c-c++-common/gomp/append-args-3.c: Likewise. * g++.dg/gomp/append-args-1.C: Likewise. * gfortran.dg/gomp/adjust-args-1.f90: Likewise. * gfortran.dg/gomp/adjust-args-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-2.f90: Likewise. * c-c++-common/gomp/append-args-6.c: New test. * c-c++-common/gomp/append-args-7.c: New test. * c-c++-common/gomp/append-args-8.c: New test. * c-c++-common/gomp/append-args-9.c: New test. * g++.dg/gomp/append-args-4.C: New test. * g++.dg/gomp/append-args-5.C: New test. * g++.dg/gomp/append-args-6.C: New test. * g++.dg/gomp/append-args-7.C: New test. * gcc.dg/gomp/append-args-1.c: New test. * gfortran.dg/gomp/append_args-1.f90: New test. * gfortran.dg/gomp/append_args-2.f90: New test. * gfortran.dg/gomp/append_args-3.f90: New test. * gfortran.dg/gomp/append_args-4.f90: New test.
2025-01-25c++/modules: Diagnose TU-local lambdas, give mangling scope to lambdas in ↵Nathaniel Shead1-1/+13
concepts This fills in a hole left in r15-6378-g9016c5ac94c557 with regards to detection of TU-local lambdas. Now that LAMBDA_EXPR_EXTRA_SCOPE is properly set for most lambdas we can use it to detect lambdas that are TU-local. CWG2988 suggests that lambdas in concept definitions should not be considered TU-local, since they are always unevaluated and should never be emitted. This patch gives these lambdas a mangling scope (though it will never be actually used in name mangling). PR c++/116568 gcc/cp/ChangeLog: * cp-tree.h (finish_concept_definition): Adjust parameters. (start_concept_definition): Declare. * module.cc (depset::hash::is_tu_local_entity): Use LAMBDA_EXPR_EXTRA_SCOPE to detect TU-local lambdas. * parser.cc (cp_parser_concept_definition): Start a lambda scope for concept definitions. * pt.cc (tsubst_lambda_expr): Namespace-scope lambdas may now have extra scope. (finish_concept_definition): Split into... (start_concept_definition): ...this new function. gcc/testsuite/ChangeLog: * g++.dg/modules/internal-4_b.C: Remove XFAIL, add lambda alias testcase. * g++.dg/modules/lambda-9.h: New test. * g++.dg/modules/lambda-9_a.H: New test. * g++.dg/modules/lambda-9_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
2025-01-25c++: Fix mangling of otherwise unattached class-scope lambdas [PR118245]Nathaniel Shead1-9/+14
This is a step closer to implementing the suggested changes for https://github.com/itanium-cxx-abi/cxx-abi/pull/85. Most lambdas defined within a class should have an extra scope of that class so that uses across different TUs are properly merged by the linker. This also needs to happen during template instantiation. While I was working on this I found some other cases where the mangling of lambdas was incorrect and causing issues, notably the testcase lambda-ctx3.C which currently emits the same mangling for the base class and member lambdas, causing mysterious assembler errors since r14-9232. One notable case not handled either here or in the ABI is what is supposed to happen with such unattached lambdas declared in member templates; see lambda-uneval22. I believe that by the C++ standard, such lambdas should also dedup across TUs, but this isn't currently implemented, and it's not clear exactly how such lambdas should mangle. Since this should only affect usage of lambdas in unevaluated contexts (a C++20 feature) this patch does not add an ABI flag to control this behaviour. PR c++/118245 gcc/cp/ChangeLog: * cp-tree.h (LAMBDA_EXPR_EXTRA_SCOPE): Adjust comment. * parser.cc (cp_parser_class_head): Start (and do not finish) lambda scope for all valid types. (cp_parser_class_specifier): Finish lambda scope after parsing members instead. * pt.cc (instantiate_class_template): Add lambda scoping. gcc/testsuite/ChangeLog: * g++.dg/abi/lambda-ctx3.C: New test. * g++.dg/cpp2a/lambda-uneval22.C: New test. * g++.dg/cpp2a/lambda-uneval23.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
2025-01-23c++: bogus error with nested lambdas [PR117602]Marek Polacek1-1/+2
The error here should also check that we aren't nested in another lambda; in it, at_function_scope_p() will be false. PR c++/117602 gcc/cp/ChangeLog: * cp-tree.h (current_nonlambda_scope): Add a default argument. * lambda.cc (current_nonlambda_scope): New bool parameter. Use it. * parser.cc (cp_parser_lambda_introducer): Use current_nonlambda_scope to check if the lambda is non-local. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-uneval21.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-01-23c++: Fix weird expression in test for clauses other than ↵Jakub Jelinek1-1/+1
when/default/otherwise [PR118604] Some clang analyzer warned about if (!strcmp (p, "when") == 0 && !default_p) which really looks weird, it is better to use strcmp (p, "when") != 0 or !!strcmp (p, "when"). Furthermore, as a micro optimization, it is cheaper to evaluate default_p than calling strcmp, so that can be put first in the &&. The C test for the same thing wasn't that weird, but I think for consistency it is better to use the same test rather than trying to be creative. 2025-01-23 Jakub Jelinek <jakub@redhat.com> PR c++/118604 gcc/c/ * c-parser.cc (c_parser_omp_metadirective): Rewrite condition for clauses other than when, default and otherwise. gcc/cp/ * parser.cc (cp_parser_omp_metadirective): Test !default_p first and use strcmp () != 0 rather than !strcmp () == 0.
2025-01-23c++: Fix mangling of lambdas in static data member initializers [PR107741]Nathaniel Shead1-24/+50
This fixes an issue where lambdas declared in the initializer of a static data member within the class body do not get a mangling scope of that variable; this results in mangled names that do not conform to the ABI spec. To do this, the patch splits up grokfield for this case specifically, allowing a declaration to be build and used in start_lambda_scope before parsing the initializer, so that record_lambda_scope works correctly. As a drive-by, this also fixes the issue of a static member not being visible within its own initializer. PR c++/107741 gcc/c-family/ChangeLog: * c-opts.cc (c_common_post_options): Bump ABI version. gcc/ChangeLog: * common.opt: Add -fabi-version=20. * doc/invoke.texi: Likewise. gcc/cp/ChangeLog: * cp-tree.h (start_initialized_static_member): Declare. (finish_initialized_static_member): Declare. * decl2.cc (start_initialized_static_member): New function. (finish_initialized_static_member): New function. * lambda.cc (record_lambda_scope): Support falling back to old ABI (maybe with warning). * parser.cc (cp_parser_member_declaration): Build decl early when parsing an initialized static data member. gcc/testsuite/ChangeLog: * g++.dg/abi/macro0.C: Bump ABI version. * g++.dg/abi/mangle74.C: Remove XFAILs. * g++.dg/other/fold1.C: Restore originally raised error. * g++.dg/abi/lambda-ctx2-19.C: New test. * g++.dg/abi/lambda-ctx2-19vs20.C: New test. * g++.dg/abi/lambda-ctx2-20.C: New test. * g++.dg/abi/lambda-ctx2.h: New test. * g++.dg/cpp0x/static-member-init-1.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-01-22c++: Improve cp_parser_objc_messsage_args compile timeJakub Jelinek1-8/+4
On Tue, Jan 21, 2025 at 06:47:53PM +0100, Jakub Jelinek wrote: > Indeed, I've just used what it was doing without thinking too much about it, > sorry. > addl_args = tree_cons (NULL_TREE, arg, addl_args); > with addl_args = nreverse (addl_args); after the loop might be better, > can test that incrementally. sel_args is handled the same and should have > the same treatment. Here is incremental patch to do that. Verified also on the 2 va-meth*.mm testcases (one without CPP_EMBED, one with) that -fdump-tree-gimple is the same before/after the patch. 2025-01-22 Jakub Jelinek <jakub@redhat.com> * parser.cc (cp_parser_objc_message_args): Use tree_cons with nreverse at the end for both sel_args and addl_args, instead of chainon with build_tree_list second argument.
2025-01-21c++: 'this' capture clobbered during recursive inst [PR116756]Patrick Palka1-3/+0
Here during instantiation of generic lambda's op() [with I = 0] we substitute into the call self(self, cst<1>{}) which requires recursive instantiation of the same op() [with I = 1] (which isn't deferred due to lambda's deduced return type. During this recursive instantiation, the DECL_EXPR case of tsubst_stmt clobbers LAMBDA_EXPR_THIS_CAPTURE to point to the child op()'s specialized capture proxy instead of the parent's, and the original value is never restored. So later when substituting into the openSeries call in the parent op() maybe_resolve_dummy uses the 'this' proxy belonging to the child op(), which leads to a context mismatch ICE during gimplification of the proxy. An earlier version of this patch fixed this by making instantiate_body save/restore LAMBDA_EXPR_THIS_CAPTURE during a lambda op() instantiation. But it seems cleaner to avoid overwriting LAMBDA_EXPR_THIS_CAPTURE in the first place by making it point to the non-specialized capture proxy, and instead call retrieve_local_specialization as needed, which is what this patch implements. It's natural then to not clear LAMBDA_EXPR_THIS_CAPTURE after parsing/regenerating a lambda. PR c++/116756 gcc/cp/ChangeLog: * lambda.cc (lambda_expr_this_capture): Call retrieve_local_specialization on the result of LAMBDA_EXPR_THIS_CAPTURE for a generic lambda. * parser.cc (cp_parser_lambda_expression): Don't clear LAMBDA_EXPR_THIS_CAPTURE. * pt.cc (tsubst_stmt) <case DECL_EXPR>: Don't overwrite LAMBDA_EXPR_THIS_CAPTURE with the specialized capture. (tsubst_lambda_expr): Don't clear LAMBDA_EXPR_THIS_CAPTURE afterward. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-if-lambda7.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-01-21c++: Handle CPP_EMBED in cp_parser_objc_message_args [PR118586]Jakub Jelinek1-6/+14
As the following testcases show, I forgot to handle CPP_EMBED in cp_parser_objc_message_args which is another place which can parse possibly long valid lists of CPP_COMMA separated CPP_NUMBER tokens. 2025-01-21 Jakub Jelinek <jakub@redhat.com> PR objc++/118586 gcc/cp/ * parser.cc (cp_parser_objc_message_args): Handle CPP_EMBED. gcc/testsuite/ * objc.dg/embed-1.m: New test. * obj-c++.dg/embed-1.mm: New test. * obj-c++.dg/va-meth-2.mm: New test.
2025-01-21c++: Speed up compilation of large char array initializers when not using #embedJakub Jelinek1-0/+101
The following patch (again, on top of the #embed patchset attempts to optimize compilation of large {{{,un}signed ,}char,std::byte} array initializers when not using #embed in the source. Unlike the C patch which is done during the parsing of initializers this is done when lexing tokens into an array, because C++ lexes all tokens upfront and so by the time we parse the initializers we already have 16 bytes per token allocated (i.e. 32 extra compile time memory bytes per one byte in the array). The drawback is again that it can result in worse locations for diagnostics (-Wnarrowing, -Wconversion) when initializing signed char arrays with values 128..255. Not really sure what to do about this though unlike the C case, the locations would need to be preserved through reshape_init* and perhaps till template instantiation. For #embed, there is just a single location_t (could be range of the directive), for diagnostics perhaps we could extend it to say byte xyz of the file embedded here or something like that, but the optimization done by this patch, either we'd need to bump the minimum limit at which to try it, or say temporarily allocate a location_t array for each byte and then clear it when we no longer need it or something. I've been using the same testcases as for C, with #embed of 100'000'000 bytes: time ./cc1plus -quiet -O2 -o test4a.s2 test4a.c real 0m0.972s user 0m0.578s sys 0m0.195s with xxd -i alternative of the same data without this patch it consumed around 13.2GB of RAM and time ./cc1plus -quiet -O2 -o test4b.s4 test4b.c real 3m47.968s user 3m41.907s sys 0m5.015s and the same with this patch it consumed around 3.7GB of RAM and time ./cc1plus -quiet -O2 -o test4b.s3 test4b.c real 0m24.772s user 0m23.118s sys 0m1.495s 2025-01-21 Jakub Jelinek <jakub@redhat.com> * parser.cc (cp_lexer_new_main): Attempt to optimize large sequences of CPP_NUMBER with int type and values 0-255 separated by CPP_COMMA into CPP_EMBED with RAW_DATA_CST u.value.
2025-01-21c++/modules: Check linkage of structured binding declsNathaniel Shead1-0/+1
When looking at PR c++/118513 I noticed that we don't currently check the linkage of structured binding declarations in modules. This patch adds those checks, and corrects decl_linkage to properly recognise structured binding declarations as potentially having linkage. gcc/cp/ChangeLog: * parser.cc (cp_parser_decomposition_declaration): Check linkage of structured bindings in modules. * tree.cc (decl_linkage): Structured bindings don't necessarily have no linkage. gcc/testsuite/ChangeLog: * g++.dg/modules/export-6.C: Add structured binding tests. * g++.dg/modules/hdr-2.H: Likewise. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-01-17c++: Allow pragmas in NSDMIs [PR118147]Nathaniel Shead1-1/+0
This patch removes the (unnecessary) CPP_PRAGMA_EOL case from cp_parser_cache_defarg, which currently has the result that any pragmas in the NSDMI cause an error. PR c++/118147 gcc/cp/ChangeLog: * parser.cc (cp_parser_cache_defarg): Don't error when CPP_PRAGMA_EOL. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-defer7.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-01-16c++: make finish_pseudo_destructor_expr SFINAE-aware [PR116417]Patrick Palka1-1/+2
PR c++/116417 gcc/cp/ChangeLog: * cp-tree.h (finish_pseudo_destructor_expr): Add complain parameter. * parser.cc (cp_parser_postfix_dot_deref_expression): Pass complain=tf_warning_or_error to finish_pseudo_destructor_expr. * pt.cc (tsubst_expr): Pass complain to finish_pseudo_destructor_expr. * semantics.cc (finish_pseudo_destructor_expr): Check complain before emitting a diagnostic. gcc/testsuite/ChangeLog: * g++.dg/template/pseudodtor7.C: New test. Reviewed-by: Marek Polacek <polacek@redhat.com> Reviewed-by: Jason Merrill <jason@redhat.com>