aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-14Daily bump.GCC Administrator1-0/+12
2025-06-13c++, coroutines: Handle builtin_constant_p [PR116775].Iain Sandoe1-1/+22
Since the folding of this builtin happens after the main coroutine FE lowering, we need to account for await expressions in that lowering. Since these expressions have a property of being not evaluated, but do not have the full constraints of an unevaluatated context, we want to apply the checks and then remove the await expressions so that they no longer participate in the analysis and lowering. When a builtin_constant_p call is encountered, and the operand contains any await expression, we check to see if the operand can be a constant and replace the call with its result. PR c++/116775 gcc/cp/ChangeLog: * coroutines.cc (analyze_expression_awaits): When we see a builtin_constant_p call, and that contains one or more await expressions, then replace the call with its result and discard the unevaluated operand. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr116775.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-13c++, coroutines: Ensure that the resumer is marked as can_throw.Iain Sandoe1-0/+5
We must flag that the resumer might throw (since the wrapping of the original function body unconditionally adds a try-catch/rethrow). We also add code that might throw - even when the original function body would not. TODO: We could improve code-gen by recognising cases where the combined body + initial await expressions cannot throw and omitting the unneeded try/catch/rethrow wrapper. gcc/cp/ChangeLog: * coroutines.cc (build_actor_fn): Set can_throw. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-12Daily bump.GCC Administrator1-0/+15
2025-06-12Refactor record_function_versions.Alfie Richards1-1/+9
Renames record_function_versions to add_function_version, and make it explicit that it is adding a single version to the function structure. Additionally, change the insertion point to always maintain priority ordering of the versions. This allows for removing logic for moving the default to the first position which was duplicated across target specific code and enables easier reasoning about function sets. gcc/ChangeLog: * cgraph.cc (cgraph_node::record_function_versions): Refactor and rename to... (cgraph_node::add_function_version): new function. * cgraph.h (cgraph_node::record_function_versions): Refactor and rename to... (cgraph_node::add_function_version): new function. * config/aarch64/aarch64.cc (aarch64_get_function_versions_dispatcher): Remove reordering. * config/i386/i386-features.cc (ix86_get_function_versions_dispatcher): Remove reordering. * config/riscv/riscv.cc (riscv_get_function_versions_dispatcher): Remove reordering. * config/rs6000/rs6000.cc (rs6000_get_function_versions_dispatcher): Remove reordering. gcc/cp/ChangeLog: * decl.cc (maybe_version_functions): Change record_function_versions call to add_function_version.
2025-06-12c, c++: Save 8 bytes of memory in lang_type for non-ObjC*Jakub Jelinek2-12/+19
For C++26 P2786R13 I'm afraid I'll need 4-6 new flags on class types in struct lang_type (1 bit for trivially_relocatable_if_eligible, 1 for replaceable_if_eligible, 1 for not_trivially_relocatable and 1 for not_replaceable and perhaps 2 bits whether the last 2 have been computed already) and there are just 2 bits left. The following patch is an attempt to save 8 bytes of memory in those structures when not compiling ObjC or ObjC++ (I think those are used fairly rarely and the patch keeps the sizes unmodified for those 2). The old allocations were 32 bytes for C and 120 bytes for C++. The patch moves the objc_info member last in the C++ case (it was already last in the C case), arranges for GC to skip it for C and C++ but walk for ObjC and ObjC++ and allocates or copies over just offsetof bytes instead of sizeof. 2025-06-12 Jakub Jelinek <jakub@redhat.com> gcc/c/ * c-lang.h (union lang_type::maybe_objc_info): New type. (struct lang_type): Use union maybe_objc_info info member instead of tree objc_info. * c-decl.cc (finish_struct): Allocate struct lang_type using ggc_internal_cleared_alloc instead of ggc_cleared_alloc, and use sizeof (struct lang_type) for ObjC and otherwise offsetof (struct lang_type, info) as size. (finish_enum): Likewise. gcc/cp/ * cp-tree.h (union lang_type::maybe_objc_info): New type. (struct lang_type): Use union maybe_objc_info info member instead of tree objc_info. * lex.cc (copy_lang_type): Use sizeof (struct lang_type) just for ObjC++ and otherwise offsetof (struct lang_type, info). (maybe_add_lang_type_raw): Likewise. (cxx_make_type): Formatting fix. gcc/objc/ * objc-act.h (TYPE_OBJC_INFO): Define to info.objc_info instead of objc_info. gcc/objcp/ * objcp-decl.h (TYPE_OBJC_INFO): Define to info.objc_info instead of objc_info.
2025-06-10Daily bump.GCC Administrator1-0/+7
2025-06-09c++: Fix template class lookup [PR120495, PR115605].Iain Sandoe1-11/+19
In the reported issues, using lookup_template_class () directly on (for example) the coroutine_handle identifier fails because a class-local TYPE_DECL is found. This is because, in the existing code, lookup is called with default parameters which means that class contexts are examined first. Fix this, when a context is provided by the caller, by doing lookup in namespace provided. PR c++/120495 PR c++/115605 gcc/cp/ChangeLog: * pt.cc (lookup_template_class): Honour provided namespace contexts when looking up class templates. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr120495.C: New test. * g++.dg/pr115605.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-07Daily bump.GCC Administrator1-0/+6
2025-06-06c++: recursive template with deduced return [PR120555]Jason Merrill1-3/+30
Here since r15-4120 we were prematurely complaining about the use of func within its own definiton, which is fine at instantiation time. So don't require this for function templates that are currently being defined. But keep the error for instantiations of templates that are not currently being defined, which we similarly did not diagnose before r15-4120 but other implementations do. Both of these follow the general principle from [temp.res.general]/6 that we only error in a template body if no instatiation could be well-formed. Also remove a redundant call to require_deduced_type. PR c++/120555 gcc/cp/ChangeLog: * decl2.cc (fn_being_defined, fn_template_being_defined): New. (mark_used): Check fn_template_being_defined. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-if39.C: New test.
2025-06-06Daily bump.GCC Administrator1-0/+34
2025-06-05c++: substituting fn parm redeclared with dep alias tmpl [PR120224]Patrick Palka1-2/+12
Here we declare f twice, the second time around using a dependent alias template. Due to alias template transparency these are logically the same overload. But now the function type of f (produced from the first declaration) diverges from the type of its formal parameter (produced from the subsequent redefinition) in that substituting T=int succeeds for the function type but not for the formal parameter type. This eventually causes us to produce an undiagnosed error_mark_node in the AST of the function call, leading to failure of the sanity check check added in r14-6343-g0c018a74eb1aff. Before r14-6343 we would still go on to reject the testcase later at instantiation time, from regenerate_decl_from_template, making this a regression. To fix this, it seems we just need to propagate error_mark_node upon substitution failure into the type of a PARM_DECL. PR c++/120224 gcc/cp/ChangeLog: * pt.cc (tsubst_function_decl): Return error_mark_node if substituting into the formal parameter list failed. (tsubst_decl) <case PARM_DECL>: Return error_mark_node upon TREE_TYPE substitution failure, when in a SFINAE context. Return error_mark_node upon DECL_CHAIN substitution failure. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-80.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-06-05c++: quadratic constexpr folding of arith expr [PR118340]Patrick Palka1-1/+32
Here the PR's testcase demonstrates that the cp_fully_fold calls in cp_build_binary_op (for diagnosing arithmetic overflow) lead to quadratic behavior when building up a large arithmetic constant expression. The problem is ultimately that maybe_constant_value's caching doesn't reuse intermediate values, unlike cp_fold. (And unfortunately we can't leverage the cp_fold cache in this call site because here we want to evaluate constexpr calls even in -O0, which cp_fold avoids.) This patch fixes this by making maybe_constant_value look up each operand of the given expression to see if we've previously reduced it, and if so, rebuild the expression using the (presumably) reduced operands and evaluate that. After this patch each version of the testcase from the PR compiles in ~0.1s on my machine. PR c++/118340 gcc/cp/ChangeLog: * constexpr.cc (maybe_constant_value): First try looking up each operand in the cv_cache and reusing the result. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-06-05c++, coroutines: Make analyze_fn_params into a class method.Iain Sandoe2-9/+12
This continues code cleanups and migration to encapsulation of the whole coroutine transform. gcc/cp/ChangeLog: * coroutines.cc (analyze_fn_parms): Move from free function.. (cp_coroutine_transform::analyze_fn_parms):... to method. (cp_coroutine_transform::apply_transforms): Adjust call to analyze_fn_parms. * coroutines.h: Declare analyze_fn_parms. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-05c++, coroutines: Simplify initial_await_resume_called.Iain Sandoe1-27/+16
We do not need to generate this code early, since it does not affect any of the analysis. Lowering it later takes less code, and avoids modifying the initial await expresssion which will simplify changes to analysis to deal with open PRs. gcc/cp/ChangeLog: * coroutines.cc (expand_one_await_expression): Set the initial_await_resume_called flag here. (build_actor_fn): Populate the frame accessor for the initial_await_resume_called flag. (cp_coroutine_transform::wrap_original_function_body): Do not modify the initial_await expression to include the initial_await_resume_called flag here. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-05Daily bump.GCC Administrator1-0/+7
2025-06-04c++: constexpr prvalues vs genericize [PR120502]Jason Merrill2-9/+15
Here constexpr evaluation was getting confused by the result of split_nonconstant_init, which leaves an INIT_EXPR from an empty CONSTRUCTOR to be followed by member initialization. As a result CONSTRUCTOR_NO_CLEARING was set for the time_zone, and cxx_eval_store_expression didn't set it again for the initial clobber in the basic_string constructor, so when cxx_fold_indirect_ref wants to check whether the anonymous union active member had type non_trivial_if, we see that we don't currently have a value for the anonymous union, try to add one, and fail. So let's do constexpr evaluation before split_nonconstant_init. PR c++/120502 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold_r) [TARGET_EXPR]: Do constexpr evaluation before genericize. * constexpr.cc (cxx_eval_store_expression): Add comment. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constexpr-prvalue2.C: New test.
2025-06-04Daily bump.GCC Administrator1-0/+4
2025-06-03c++: add operator| for WMB_FlagsJason Merrill1-0/+4
There are a lot of uses of | on WMB_Flags, that currently need to then be cast back to WMB_Flags. Let's avoid the need for that. gcc/cp/ChangeLog: * name-lookup.h (operator|, operator|=): Define for WMB_Flags.
2025-06-03Daily bump.GCC Administrator1-0/+51
2025-06-02c++: more __is_destructible fixes [PR107600]Jason Merrill1-1/+10
PR c++/107600 gcc/cp/ChangeLog: * method.cc (destructible_expr): Fix refs and arrays of unknown bound. gcc/testsuite/ChangeLog: * g++.dg/ext/is_destructible2.C: Add more cases.
2025-06-02c++: constinit diagnostic regression [PR120506]Jason Merrill1-2/+1
In r16-57 I thought it was unnecessary to mention incomplete initialization after another diagnostic, but actually it's useful elaboration. PR c++/120506 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_outermost_constant_expr): Always check CONSTRUCTOR_NO_CLEARING. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constinit21.C: New test.
2025-06-02c++, coroutines: Some cleanups in build_actor.Iain Sandoe1-37/+21
We were incorrectly guarding all the frame cleanups on the basis of frame_needs_free (which is always set for the present code-gen since we have no allocation elision). The net result being that the (incorrect) code was behaving as expected. We built, but never used, a label for the frame destruction; in practice it is never triggered independently of the promise and argument copy destruction. Finally there are a few instances where we had been building expressions manually rather than using higher-level APIs. gcc/cp/ChangeLog: * coroutines.cc (build_actor_fn): Remove an unused label, guard the frame deallocation correctly, use simpler APIs to build if and return statements. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-02c++: Emit an error for attempted constexpr co_await [PR118903].Iain Sandoe1-0/+3
We checked that the coroutine expressions were not suitable for constexpr, but did not emit and error when needed. PR c++/118903 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Emit an error when co_await et. al. are used in constexpr contexts. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr118903.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-02c++: Add co_await, co_yield and co_return to dump_expr.Iain Sandoe1-0/+21
These were omitted there as an oversight, most of the error handling for the coroutines code is specific rather than using generic %qE etc. gcc/cp/ChangeLog: * error.cc (dump_expr): Add co_await, co_yield and co_return. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-06-02c++: __is_destructible fixes [PR107600]Jason Merrill1-5/+16
destructible_expr was wrongly assuming that TO is a class type. When is_xible_helper was added in r8-742 it returned early for abstract class types, which is correct for __is_constructible, but not __is_assignable or (now) __is_destructible. PR c++/107600 gcc/cp/ChangeLog: * method.cc (destructible_expr): Handle non-classes. (constructible_expr): Check for abstract class here... (is_xible_helper): ...not here. gcc/testsuite/ChangeLog: * g++.dg/ext/is_destructible2.C: New test.
2025-06-02c++: __has_trivial_destructor regressionJason Merrill1-0/+1
We don't want the new call to get_dtor to cause function instantiation. PR c++/107600 gcc/cp/ChangeLog: * semantics.cc (trait_expr_value) [CPTK_HAS_TRIVIAL_DESTRUCTOR]: Add cp_unevaluated. gcc/testsuite/ChangeLog: * g++.dg/ext/has_trivial_destructor-3.C: New test.
2025-06-02OpenMP: Handle more cases in user/condition selectorSandra Loosemore4-13/+42
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.
2025-05-31Daily bump.GCC Administrator1-0/+61
2025-05-30c++: more xobj lambda 'this' capture [PR113563]Jason Merrill1-11/+17
Nathaniel shared a more extensive test, which revealed more needed fixes. PR c++/113563 gcc/cp/ChangeLog: * lambda.cc (lambda_capture_field_type): Handle 'this' normally. (build_capture_proxy): Special-case 'this' by-ref capture more. (nonlambda_method_basetype): Look through xobj lambdas. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-lambda17.C: New test.
2025-05-30OpenMP: C++ "declare mapper" supportJulian Brown10-25/+620
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. 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_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_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-10.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. * g++.dg/gomp/declare-mapper-3.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. Co-authored-by: Tobias Burnus <tburnus@baylibre.com>
2025-05-30Daily bump.GCC Administrator1-0/+72
2025-05-29diagnostics: use unique_ptr for m_format_postprocessorDavid Malcolm1-5/+5
No functional change intended. gcc/cp/ChangeLog: * error.cc (cxx_format_postprocessor::clone): Update to use unique_ptr. (cxx_dump_pretty_printer::cxx_dump_pretty_printer): Likewise. (cxx_initialize_diagnostics): Likewise. gcc/ChangeLog: * pretty-print.cc (pretty_printer::pretty_printer): Use "nullptr" rather than "NULL". Remove explicit delete of m_format_postprocessor. * pretty-print.h (format_postprocessor::clone): Use unique_ptr. (pretty_printer::set_format_postprocessor): New. (pretty_printer::m_format_postprocessor): Use unique_ptr. (pp_format_postprocessor): Update for use of unique_ptr, removing reference from return type. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-05-29c++: xobj lambda 'this' capture [PR113563]Jason Merrill2-18/+11
Various places were still making assumptions that we could get to the 'this' capture through current_class_ref in a lambda op(), which is incorrect for an explicit object op(). PR c++/113563 gcc/cp/ChangeLog: * lambda.cc (build_capture_proxy): Check pointerness of the member, not the proxy type. (lambda_expr_this_capture): Don't assume current_class_ref. (nonlambda_method_basetype): Likewise. * semantics.cc (finish_non_static_data_member): Don't assume TREE_TYPE (object) is set. (finish_this_expr): Check current_class_type for lambda, not current_class_ref. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-lambda16.C: New test.
2025-05-29c++, coroutines: Make a check more specific [PR109283].Iain Sandoe1-3/+5
The check was intended to assert that we had visited contained ternary expressions with embedded co_awaits, but had been made too general - and therefore was ICEing on code that was actually OK. Fixed by checking specifically that no co_awaits embedded. PR c++/109283 gcc/cp/ChangeLog: * coroutines.cc (find_any_await): Only save the statement pointer if the caller passes a place for it. (flatten_await_stmt): When checking that ternary expressions have been handled, also check that they contain a co_await. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr109283.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-05-29c++: C++17 constexpr lambda and goto/staticJason Merrill3-14/+24
We only want the error for these cases for functions explicitly declared constexpr, but we still want to set invalid_constexpr on C++17 lambdas so maybe_save_constexpr_fundef doesn't make them implicitly constexpr. The potential_constant_expression_1 change isn't necessary for this test, but still seems correct. gcc/cp/ChangeLog: * decl.cc (start_decl): Also set invalid_constexpr for maybe_constexpr_fn. * parser.cc (cp_parser_jump_statement): Likewise. * constexpr.cc (potential_constant_expression_1): Ignore goto to an artificial label. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-lambda29.C: New test.
2025-05-29OpenMP: 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.
2025-05-29OpenMP: 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.
2025-05-29c++, coroutines: Delete now unused code for parm guards.Iain Sandoe2-12/+1
Since r16-775-g18df4a10bc9694 we use nested cleanups to handle parameter copy destructors in the ramp (and pass a list of cleanups required to the actor which will only be invoked if the parameter copies were all correctly built - and therefore does not need to guard destructors either. This deletes the provisions for frame parameter copy destructor guards. gcc/cp/ChangeLog: * coroutines.cc (analyze_fn_parms): No longer create a parameter copy guard var. * coroutines.h (struct param_info): Remove the entry for the parameter copy destructor guard. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-05-29c++, coroutines: Fix identification of coroutine ramps [PR120453].Iain Sandoe2-1/+5
The existing implementation, incorrectly, tried to use DECL_RAMP_FN in check_return_expr to determine if we are handling a ramp func. However, that query is only set for the resume/destroy functions. Replace the use of DECL_RAMP_FN with a new query. PR c++/120453 gcc/cp/ChangeLog: * cp-tree.h (DECL_RAMP_P): New. * typeck.cc (check_return_expr): Use DECL_RAMP_P instead of DECL_RAMP_FN. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr120453.C: New test. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-05-28c++: add __is_*destructible builtins [PR107600]Jason Merrill4-0/+47
Typically "does this class have a trivial destructor" is the wrong question to ask, we rather want "can I destroy this class trivially", thus the std::is_trivially_destructible standard trait. Let's provide a builtin for it, and complain about asking whether a deleted destructor is trivial. Clang and MSVC also have these traits. PR c++/107600 gcc/cp/ChangeLog: * cp-trait.def (IS_DESTRUCTIBLE, IS_NOTHROW_DESTRUCTIBLE) (IS_TRIVIALLY_DESTRUCTIBLE): New. * constraint.cc (diagnose_trait_expr): Explain them. * method.cc (destructible_expr): New. (is_xible_helper): Use it. * semantics.cc (finish_trait_expr): Handle new traits. (trait_expr_value): Likewise. Complain about asking whether a deleted dtor is trivial. gcc/testsuite/ChangeLog: * g++.dg/ext/is_destructible1.C: New test.
2025-05-29Daily bump.GCC Administrator1-0/+13
2025-05-28c++: modules and using-directivesJason Merrill4-3/+99
We weren't representing 'using namespace' at all in modules, which broke some of the <chrono> literals tests. This only represents exported using-declarations; others should be irrelevant to importers, as any name lookup in the imported module that would have cared about them was done while compiling the header unit. I experimented with various approaches to representing them; this patch handles them in read/write_namespaces, after the namespaces themselves. I spent a while pondering how to deal with the depset code in order to connect them, but then realized it would be simpler to refer to them based on their index in the array of namespaces. Any using-directives from an indirect import are ignored, so in an export import, any imported using-directives are exported again. gcc/cp/ChangeLog: * module.cc (module_state::write_namespaces): Write using-directives. (module_state::read_namespaces): And read them. * name-lookup.cc (add_using_namespace): Add overload. Build a USING_DECL for modules. (name_lookup::search_usings, name_lookup::queue_usings) (using_directives_contain_std_p): Strip the USING_DECL. * name-lookup.h: Declare it. * parser.cc (cp_parser_import_declaration): Set MK_EXPORTING for export import. gcc/testsuite/ChangeLog: * g++.dg/modules/namespace-8_a.C: New test. * g++.dg/modules/namespace-8_b.C: New test. * g++.dg/modules/namespace-9_a.C: New test. * g++.dg/modules/namespace-9_b.C: New test. * g++.dg/modules/namespace-10_a.C: New test. * g++.dg/modules/namespace-10_b.C: New test. * g++.dg/modules/namespace-10_c.C: New test. * g++.dg/modules/namespace-11_a.C: New test. * g++.dg/modules/namespace-11_b.C: New test. * g++.dg/modules/namespace-11_c.C: New test.
2025-05-28Daily bump.GCC Administrator1-0/+5
2025-05-27c++, coroutines: Fix typos in TRUTH_ANDIF_EXPRs.Iain Sandoe1-3/+3
These were typoed to TRUTH_AND_EXPR (and then that got copied). gcc/cp/ChangeLog: * coroutines.cc (cp_coroutine_transform::build_ramp_function): Replace TRUTH_AND_EXPR with TRUTH_ANDIF_EXPR in three places. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-05-27Daily bump.GCC Administrator1-0/+21
2025-05-26OpenMP/C++: Avoid ICE for BIND_EXPR with empty BIND_EXPR_BLOCK [PR120413]Tobias Burnus1-4/+4
PR c++/120413 gcc/cp/ChangeLog: * semantics.cc (finish_omp_target_clauses_r): Handle BIND_EXPR with empty BIND_EXPR_BLOCK. gcc/testsuite/ChangeLog: * g++.dg/gomp/target-4.C: New test.
2025-05-26c++: add -fdump-lang-tinstJason Merrill3-17/+97
This patch adds a dump with a trace of template instantiations, indented based on the depth of recursive instantiation. -lineno adds the location that triggered the instantiation, -details adds non-instantiation sbustitutions. The instantiate_pending_templates change is to avoid a bunch of entries for reopening tinst scopes that we then don't instantiate anything with; it also seems a bit cleaner this way. gcc/cp/ChangeLog: * cp-tree.h: Declare tinst_dump_id. * cp-objcp-common.cc (cp_register_dumps): Set it. * pt.cc (push_tinst_level_loc): Dump it. (reopen_tinst_level): Here too. (tinst_complete_p): New. (instantiate_pending_templates): Don't reopen_tinst_level for already-complete instantiations. gcc/ChangeLog: * doc/invoke.texi: Move C++ -fdump-lang to C++ section. Add -fdump-lang-tinst.
2025-05-26c++: add cxx_dump_pretty_printerJason Merrill2-0/+50
A class to simplify implementation of -fdump-lang-foo with support for pp_printf using %D and such. gcc/cp/ChangeLog: * cp-tree.h (class cxx_dump_pretty_printer): New. * error.cc (cxx_dump_pretty_printer): Ctor/dtor definitions.
2025-05-26Daily bump.GCC Administrator1-0/+5