aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2020-05-14c++: Missing SFINAE with lookup_fnfields [PR78446]Patrick Palka10-13/+35
Here we're failing to do SFINAE in build_op_call when looking up the class's operator() via lookup_fnfields, which calls lookup_member always with complain=tf_warning_or_error; from there we would complain about an ambiguous lookup for operator(). This patch fixes this by adding a tsubst_flags_t parameter to lookup_fnfields and adjusting all its callers appropriately. gcc/cp/ChangeLog: PR c++/78446 * call.c (build_op_call): Pass complain to lookup_fnfields. (build_special_member_call): Likewise. * class.c (type_requires_array_cookie): Pass tf_warning_or_error to lookup_fnfields. * cp-tree.h (lookup_fnfields): Add tsubst_flags_t parameter. * except.c (build_throw): Pass tf_warning_or_error to lookup_fnfields. * init.c (build_new_1): Pass complain to lookup_fnfields. * method.c (locate_fn_flags): Likewise. * name-lookup.c (lookup_name_real_1): Pass tf_warning_or_error to lookup_fnfields. * pt.c (tsubst_baselink): Pass complain to lookup_fnfields. * search.c (lookup_fnfields): New 'complain' parameter. Pass it to lookup_member. gcc/testsuite/ChangeLog: PR c++/78446 * g++.dg/template/sfinae31.C: New test.
2020-05-14c++: Missed c++2a->20 changeNathan Sidwell2-13/+10
Jason missed a c++2a mention. I couldn't resist changing the loop following to place the initializers inside the fors. * parser.c (cp_parser_diagnose_invalid_typename): Mention std=c++20 not 2a, reformat dependent binfo inform loops.
2020-05-14c++: Simplify tsubst_template_declNathan Sidwell2-36/+37
tsubst_template_decl's control flow was also confusing. This reorders and flattens some of the conditionals. * pt.c (tsubst_template_decl): Reorder and commonize some control paths.
2020-05-14c++: Simplify tsubst_friend_functionNathan Sidwell2-15/+15
tsubst_friend_function's control flow was a little complicated. This simplifies it, primarily by using more RAII. * pt.c (tsubst_friend_function): Simplify control flow.
2020-05-14c++: simplify lookup_template_class_1Nathan Sidwell2-3/+5
We were checking TYPE_NAME and then copying it if not null. Just copy it, and then see if we got null. * pt.c (lookup_template_class_1): Remove unnecessary else by simply grabbing TYPE_NAME earlier.
2020-05-14c++: Adjust push_template_decl_realNathan Sidwell2-14/+25
Push_template_decl_real's friend-pushing logic was confusing me. This is more understandable. Fix a latent type bug I disovered. * pt.c (push_template_decl_real): Adjust friend pushing logic. Reinit template type.
2020-05-14c++: Improve build_template_declNathan Sidwell2-10/+11
I discovered all the users of build_template_decl were explicitly setting the RESULT and TYPE fields of the built decl. Let's just have build_template_decl do that in the first place. * pt.c (build_template_decl): Init DECL_TEMPLATE_RESULT & TREE_TYPE here ... (process_partial_specialization): ... not here ... (push_template_decl_real, add_inherited_template_parms) (build_deduction_guide): ... or here.
2020-05-14openmp: Also implicitly mark as declare target to functions mentioned in ↵Jakub Jelinek2-0/+8
target regions OpenMP 5.0 also specifies that functions referenced from target regions (except for target regions with device(ancestor:)) are also implicitly declare target to. This patch implements that. 2020-05-14 Jakub Jelinek <jakub@redhat.com> * function.h (struct function): Add has_omp_target bit. * omp-offload.c (omp_discover_declare_target_fn_r): New function, old renamed to ... (omp_discover_declare_target_tgt_fn_r): ... this. (omp_discover_declare_target_var_r): Call omp_discover_declare_target_tgt_fn_r instead of omp_discover_declare_target_fn_r. (omp_discover_implicit_declare_target): Also queue functions with has_omp_target bit set, for those walk with omp_discover_declare_target_fn_r, for declare target to functions walk with omp_discover_declare_target_tgt_fn_r. gcc/c/ * c-parser.c (c_parser_omp_target): Set cfun->has_omp_target. gcc/cp/ * cp-gimplify.c (cp_genericize_r): Set cfun->has_omp_target. gcc/fortran/ * trans-openmp.c: Include function.h. (gfc_trans_omp_target): Set cfun->has_omp_target. libgomp/ * testsuite/libgomp.c-c++-common/target-40.c: New test.
2020-05-13c++: SFINAE for invalid delete-expression [PR79706]Patrick Palka2-2/+14
This fixes SFINAE when substitution yields an invalid delete-expression due to the pertinent deallocation function being marked deleted or otherwise inaccessible. We need to check for an erroneous result from build_op_delete_call and exit early in that case, so that we don't build a COND_EXPR around the erroneous result which finish_decltype_type would then quietly accept. gcc/cp/ChangeLog: PR c++/79706 * init.c (build_vec_delete_1): Just return error_mark_node if deallocate_expr is error_mark_node. (build_delete): Just return error_mark_node if do_delete is error_mark_node. gcc/testsuite/ChangeLog: PR c++/79706 * g++.dg/template/sfinae30.C: New test.
2020-05-13c++: premature requires-expression folding [PR95020]Patrick Palka2-3/+8
In the testcase below we're prematurely folding away the requires-expression to 'true' after substituting in the function's template arguments, but before substituting in the lambda's deduced template arguments. This patch removes the uses_template_parms check when deciding in tsubst_requires_expr whether to keep around a new requires-expression. Regardless of whether the template arguments are dependent, there still might be more template parameters to later substitute in (as in the below testcase) and even if not, tsubst_expr doesn't perform full semantic processing unless !processing_template_decl, so we should still wait until then to fold away the requires-expression. gcc/cp/ChangeLog: PR c++/95020 * constraint.c (tsubst_requires_expr): Produce a new requires-expression when processing_template_decl, even if template arguments are not dependent. gcc/testsuite/ChangeLog: PR c++/95020 * g++/cpp2a/concepts-lambda7.C: New test.
2020-05-13c++: explicit(bool) malfunction with dependent expression [PR95066]Marek Polacek2-0/+7
I forgot to set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P when merging two function declarations and as a sad consequence, we never tsubsted the dependent explicit-specifier in tsubst_function_decl, leading to disregarding the explicit-specifier altogether, and wrongly accepting this test. PR c++/95066 * decl.c (duplicate_decls): Set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P. * g++.dg/cpp2a/explicit16.C: New test.
2020-05-13c++: Template arg comparisonNathan Sidwell2-9/+11
When fixing up the template specialization hasher I was confused by the control flow through template_args_equal. This reorders the category checking, so it is clearer as to what kind of node can reach which point. * pt.c (template_args_equal): Reorder category checking for clarity.
2020-05-13c++: Simplify typedef access checkingNathan Sidwell2-39/+38
I discovered that the template typedef access check was rather more expensive than needed. The call of get_types_needed_access_check in the FOR_EACH_VEC_SAFE_ELT is the moral equivalent of 'for (size_t pos = 0; pos != strlen (string); pos++)'. Let's not do that. * pt.c (perform_typedefs_access_check): Cache expensively calculated object references. (check_auto_in_tmpl_args): Just assert we do not get unexpected nodes, rather than silently do nothing. (append_type_to_template_for_access): Likewise, cache expensie object reference.
2020-05-13c++: Simplify canonical_type_parameterNathan Sidwell2-16/+10
Use a single vec_safe_grow_cleared, rather than that or a vec_alloc. Use a for loop that returns early. * pt.c (canonical_type_parameter): Simplify.
2020-05-13c++: Formatting fixups & some simplifications.Nathan Sidwell3-45/+60
A bunch of minor reformatting, simplifications or change to checking_asserts. * pt.c (spec_hash_table): New typedef. (decl_specializations, type_specializations): Use it. (retrieve_specialization): Likewise. (register_specialization): Remove unnecessary casts. (push_template_decl_real): Reformat. (instantiate_class_template_1): Use more RAII. (make_argument_pack): Simplify. (instantiate_template_1): Use gcc_checking_assert for expensive asserts. (instantiate_decl): Likewise. (resolve_typename_type): Reformat comment. * semantics.c (struct deferred_access): Remove unnecessary GTY on member. (begin_class_definition): Fix formatting.
2020-05-13c++: Replace "C++2a" with "C++20".Jason Merrill15-148/+154
C++20 isn't final quite yet, but all that remains is formalities, so let's go ahead and change all the references. I think for the next C++ standard we can just call it C++23 rather than C++2b, since the committee has been consistent about time-based releases rather than feature-based. gcc/c-family/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * c.opt (std=c++20): Make c++2a the alias. (std=gnu++20): Likewise. * c-common.h (cxx_dialect): Change cxx2a to cxx20. * c-opts.c: Adjust. * c-cppbuiltin.c: Adjust. * c-ubsan.c: Adjust. * c-warn.c: Adjust. gcc/cp/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * call.c, class.c, constexpr.c, constraint.cc, decl.c, init.c, lambda.c, lex.c, method.c, name-lookup.c, parser.c, pt.c, tree.c, typeck2.c: Change cxx2a to cxx20. libcpp/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * include/cpplib.h (enum c_lang): Change CXX2A to CXX20. * init.c, lex.c: Adjust.
2020-05-12c++: Function found via ADL when it should not [PR95074]Marek Polacek2-10/+23
I noticed that we don't implement [basic.lookup.argdep]/3: quite correctly; it says "If X (the lookup set produced by unqualified lookup) contains -- a block-scope function declaration that is not a using-declaration [...] then Y (the lookup set produced by ADL) is empty." but we were still performing ADL in fn1 in the attached test. The problem was that we were only looking at the first function in the overload set which in this case happened to be a using-declaration, and those don't suppress ADL. We have to look through the whole set to find out if unqualified lookup found a block-scope function declaration, or a member function declaration. PR c++/95074 * parser.c (cp_parser_postfix_expression) <case CPP_OPEN_PAREN>: When looking for a block-scope function declaration, look through the whole set, not just the first function in the overload set. * g++.dg/lookup/koenig15.C: New test.
2020-05-12openmp: Fix up handling of DECL_OMP_PRIVATIZED_MEMBER for bit-fields [PR95063]Jakub Jelinek2-0/+12
The r11-15 change broke this testcase, as it now asserts type is equal to the type of the DECL_VALUE_EXPR, but for DECL_OMP_PRIVATIZED_MEMBER artificial vars mapping to bitfields it wasn't. Fixed by changing the DECL_OMP_PRIVATIZED_MEMBER var type in that case. 2020-05-12 Jakub Jelinek <jakub@redhat.com> PR c++/95063 * pt.c (tsubst_decl): Deal with DECL_OMP_PRIVATIZED_MEMBER for a bit-field. * g++.dg/gomp/pr95063.C: New test.
2020-05-11c++: Fix specialization of constrained member template.Jason Merrill2-3/+31
The resolution of comment CA104 clarifies that we need to do direct substitution of constraints in order to determine which member template corresponds to an explicit specialization. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> Resolve C++20 NB comment CA104 * pt.c (determine_specialization): Compare constraints for specialization of member template of class instantiation.
2020-05-11c++: tree walk into TYPENAME_TYPE.Jason Merrill4-22/+45
While looking at 92583/92654 it occurred to me that typename types needed the same fix. So extract_locals_r also needs to see the TYPE_CONTEXT of a TYPENAME_TYPE. But it must not look through a typedef. Most tree walking in the front end wants to walk through the syntactic form of a type of expression, and doesn't care about the type referred to by a typedef. But min_vis_r does care. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> PR c++/92583 PR c++/92654 * tree.c (cp_walk_subtrees): Stop at typedefs. Handle TYPENAME_TYPE here. * pt.c (find_parameter_packs_r): Not here. (for_each_template_parm_r): Clear *walk_subtrees. * decl2.c (min_vis_r): Look through typedefs.
2020-05-11c++: Better diagnostic in converted const expr.Jason Merrill2-17/+30
This improves the diagnostic from error: could not convert ‘((A<>*)(void)0)->A<>::e’ from ‘<unresolved overloaded function type>’ to ‘bool’ to error: cannot convert ‘A<>::e’ from type ‘void (A<>::)()’ to type ‘bool’ gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * call.c (implicit_conversion_error): Split out from... (perform_implicit_conversion_flags): ...here. (build_converted_constant_expr_internal): Use it.
2020-05-11c++: Use of 'this' in parameter declaration [PR90748]Jason Merrill2-51/+46
We were incorrectly accepting the use of 'this' at parse time and then crashing when we tried to instantiate it. It is invalid because 'this' is not in scope until after the function-cv-quals. So let's hoist setting current_class_ptr up from cp_parser_late_return_type_opt into cp_parser_direct_declarator where it can work for noexcept as well. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> PR c++/90748 * parser.c (inject_parm_decls): Set current_class_ptr here. (cp_parser_direct_declarator): And here. (cp_parser_late_return_type_opt): Not here. (cp_parser_noexcept_specification_opt): Nor here. (cp_parser_exception_specification_opt) (cp_parser_late_noexcept_specifier): Remove unneeded parameters.
2020-05-11c++: Make references to __cxa_pure_virtual weak.Jason Merrill2-0/+8
If a program has no other dependencies on libstdc++, we shouldn't require it just for __cxa_pure_virtual, which is only there to give a prettier diagnostic before crashing the program; resolving the reference to NULL will also crash, just without the diagnostic. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * decl.c (cxx_init_decl_processing): Call declare_weak for __cxa_pure_virtual.
2020-05-11c++: Improve print_tree of static_assert.Jason Merrill3-15/+19
We weren't printing the condition and message of a STATIC_ASSERT. It's also unnecessary to duplicate the code for instantiating a STATIC_ASSERT between tsubst_expr and instantiate_class_template_1. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * pt.c (instantiate_class_template_1): Call tsubst_expr for STATIC_ASSERT member. * ptree.c (cxx_print_xnode): Handle STATIC_ASSERT.
2020-05-11c++: Remove redundant code.Jason Merrill2-6/+5
We walk the lambda captures in cp_walk_subtrees, so we don't also need to walk them here. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * pt.c (find_parameter_packs_r) [LAMBDA_EXPR]: Remove redundant walking of capture list.
2020-05-11c++: Remove LOOKUP_EXPLICIT_TMPL_ARGS.Jason Merrill3-15/+10
This flag is redundant with the explicit_targs field in the overload candidate information. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * cp-tree.h (LOOKUP_EXPLICIT_TMPL_ARGS): Remove. * call.c (build_new_function_call): Don't set it. (build_new_method_call_1): Likewise. (build_over_call): Check cand->explicit_targs instead.
2020-05-11c++: Tweak VLA representation.Jason Merrill2-5/+14
If we put the SAVE_EXPR for a VLA size inside the MINUS_EXPR rather than outside, it will work better with constant folding. The equivalent change was made in the C front-end in 2004, in commit r0-64535-g8b0b9aefd29dfe6398857bcf5628662e2f0e21f6 gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * decl.c (compute_array_index_type_loc): Stabilize before building the MINUS_EXPR.
2020-05-11c++: Avoid unnecessary deprecated warnings.Jason Merrill2-7/+16
There's no need to warn that a deprecated function uses a deprecated type, that just adds noise. We were preventing that in start_decl, but that didn't help member declarations that go through grokfield. So handle it in grokdeclarator instead, which is shared between them. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * decl.c (grokdeclarator): Adjust deprecated_state here. (start_decl): Not here.
2020-05-08coroutines: Update TREE_SIDE_EFFECTS on inserted bind exprs.Iain Sandoe2-5/+18
There are several places where we insert bind expressions while making the coroutine AST transforms. These should be marked as having side-effects where relevant, which had been omitted. This leads to at least one failure in the cppcoros test suite, where a loop body is dropped in gimplification because it is not marked. gcc/cp/ChangeLog: 2020-05-08 Iain Sandoe <iain@sandoe.co.uk> PR c++/95003 * coroutines.cc (build_actor_fn): Ensure that bind scopes are marked as having side-effects where necessary. (replace_statement_captures): Likewise. (morph_fn_to_coro): Likewise. gcc/testsuite/ChangeLog: 2020-05-08 Iain Sandoe <iain@sandoe.co.uk> PR c++/95003 * g++.dg/coroutines/torture/pr95003.C: New test.
2020-05-08c++: No news is good newsNathan Sidwell2-408/+2
The NEWS file hasn't been updated since GCC 3.4. It's not very news-worthy. * NEWS: Delete, it is so stale.
2020-05-08EOF has a locationNathan Sidwell2-4/+6
There's no need to special-case EOF's location. For the complete file we give it a legitimate location. And for deferred parses we now zap a temporary EOF onto the next token, so we can just use its location anyway. gcc/cp/ * parser.c (cp_lexer_set_source_position_from_token): EOF has a location too. gcc/testsuite/ * c-c++-common/raw-string-6.c: Adjust EOF error location. * g++.dg/cpp0x/decltype63.C: Likewise. * g++.dg/cpp0x/gen-attrs-64.C: Likewise. * g++.dg/cpp0x/pr68726.C: Likewise. * g++.dg/cpp0x/pr78341.C: Likewise. * g++.dg/cpp1y/pr65202.C: Likewise. * g++.dg/cpp1z/class-deduction44.C: Likewise. * g++.dg/diagnostic/unclosed-extern-c.C: Likewise. * g++.dg/diagnostic/unclosed-function.C: Likewise. * g++.dg/diagnostic/unclosed-namespace.C: Likewise. * g++.dg/diagnostic/unclosed-struct.C: Likewise. * g++.dg/ext/pr84598.C: Likewise. * g++.dg/other/switch4.C: Likewise. * g++.dg/parse/crash10.C: Likewise. * g++.dg/parse/crash18.C: Likewise. * g++.dg/parse/crash35.C: Likewise. * g++.dg/parse/crash59.C: Likewise. * g++.dg/parse/crash61.C: Likewise. * g++.dg/parse/crash67.C: Likewise. * g++.dg/parse/ctor3.C: Likewise. * g++.dg/parse/error14.C: Likewise. * g++.dg/parse/error5.C: Likewise. * g++.dg/parse/error56.C: Likewise. * g++.dg/parse/invalid1.C: Likewise. * g++.dg/parse/parameter-declaration-1.C: Likewise. * g++.dg/parse/parser-pr28152-2.C: Likewise. * g++.dg/parse/parser-pr28152.C: Likewise. * g++.dg/parse/pr68722.C: Likewise. * g++.dg/pr46852.C: Likewise. * g++.dg/pr46868.C: Likewise. * g++.dg/template/crash115.C: Likewise. * g++.dg/template/crash43.C: Likewise. * g++.dg/template/error-recovery1.C: Likewise. * g++.dg/template/error57.C: Likewise. * g++.old-deja/g++.other/crash31.C: Likewise.
2020-05-07coroutines: Improve error recovery [PR94817, PR94829].Iain Sandoe3-16/+47
When we have completely missing key information (e.g. the coroutine_traits) or a partially transformed function body, we need to try and balance returning useful information about failures with the possibility that some part of the diagnostics machinery or following code will not be able to handle the state. The PRs (and revised testcase) point to cases where that processing has failed. This revises the process to avoid special handling for the ramp, and falls back on the same code used for regular function fails. There are test-cases (in addition to the ones for the PRs) that now cover all early exit points [where the transforms are considered to have failed in a manner that does not allow compilation to continue]. gcc/cp/ChangeLog: 2020-05-07 Iain Sandoe <iain@sandoe.co.uk> PR c++/94817 PR c++/94829 * coroutines.cc (morph_fn_to_coro): Set unformed outline functions to error_mark_node. For early error returns suppress warnings about missing ramp return values. Fix reinstatement of the function body on pre-existing initial error. * decl.c (finish_function): Use the normal error path for fails in the ramp function, do not try to compile the helpers if the transform fails. gcc/testsuite/ChangeLog: 2020-05-07 Iain Sandoe <iain@sandoe.co.uk> PR c++/94817 PR c++/94829 * g++.dg/coroutines/coro-missing-final-suspend.C: New test. * g++.dg/coroutines/coro-missing-initial-suspend.C: New test. * g++.dg/coroutines/coro-missing-promise-yield.C: Check for continuation of compilation. * g++.dg/coroutines/coro-missing-promise.C: Likewise. * g++.dg/coroutines/coro-missing-ret-value.C: Likewise * g++.dg/coroutines/coro-missing-ret-void.C: Likewise * g++.dg/coroutines/coro-missing-ueh-3.C: Likewise * g++.dg/coroutines/pr94817.C: New test. * g++.dg/coroutines/pr94829.C: New test.
2020-05-07c++: Detect long double -> double narrowing [PR94590]Marek Polacek2-1/+15
This PR points out that we don't detect long double -> double narrowing when long double happens to have the same precision as double; on x86_64 this can be achieved by -mlong-double-64. [dcl.init.list]#7.2 specifically says "from long double to double or float, or from double to float", but check_narrowing only checks TYPE_PRECISION (type) < TYPE_PRECISION (ftype) so we need to handle the other cases too, e.g. by same_type_p as in the following patch. PR c++/94590 - Detect long double -> double narrowing. * typeck2.c (check_narrowing): Detect long double -> double narrowing even when double and long double have the same precision. Make it handle conversions to float too. * g++.dg/cpp0x/Wnarrowing18.C: New test.
2020-05-07c++: Fix crash with template spec in different namespace [PR94255]Marek Polacek2-1/+12
This is an ICE on invalid, because we're specializing S::foo in the wrong namespace. cp_parser_class_specifier_1 parses S::foo in M and then it tries to push the nested-name-specifier of foo, which is S. By that, we're breaking the assumption of push_inner_scope that the pushed scope must be a scope nested inside current scope: current scope is M, but the namespace context of S is N, and N is not nested in M, so we fell into an infinite loop in push_inner_scope_r. (cp_parser_class_head called check_specialization_namespace which already gave a permerror.) PR c++/94255 * parser.c (cp_parser_class_specifier_1): Check that the scope is nested inside current scope before pushing it. * g++.dg/template/spec41.C: New test.
2020-05-07c++: Implement P1957R2, T* to bool should be considered narrowing.Marek Polacek2-3/+10
This was approved in the Prague 2020 WG21 meeting so let's adjust the comment. Since it's supposed to be a DR I think we should no longer limit it to C++20. P1957R2 * typeck2.c (check_narrowing): Consider T* to bool narrowing in C++11 and up. * g++.dg/cpp0x/initlist92.C: Don't expect an error in C++20 only.
2020-05-07c++: Fix spelling of non-staticMarek Polacek8-16/+21
I was looking at DR 296 and noticed that we say "nonstatic" instead of "non-static", which is the version the standard uses. So this patch fixes the spelling throughout the front end. Did not check e.g. non-dependent or any other. * decl.c (grok_op_properties): Fix spelling of non-static. * typeck.c (build_class_member_access_expr): Likewise. * g++.dg/other/operator1.C: Adjust expected message. * g++.dg/overload/operator2.C: Likewise. * g++.dg/template/error30.C: Likewise. * g++.old-deja/g++.jason/operator.C: Likewise.
2020-05-07extend DECL_GIMPLE_REG_P to all typesRichard Biener2-1/+6
This extends DECL_GIMPLE_REG_P to all types so we can clear TREE_ADDRESSABLE even for integers with partial defs, not just complex and vector variables. To make that transition easier the patch inverts DECL_GIMPLE_REG_P to DECL_NOT_GIMPLE_REG_P since that makes the default the current state for all other types besides complex and vectors. For the testcase in PR94703 we're able to expand the partial def'ed local integer to a register then, producing a single movl rather than going through the stack. On i?86 this execute FAILs gcc.dg/torture/pr71522.c because we now expand a round-trip through a long double automatic var to a register fld/fst which normalizes the value. For that during RTL expansion we're looking for problematic punnings of decls and avoid pseudos for those - I chose integer or BLKmode accesses on decls with modes where precision doesn't match bitsize which covers the XFmode case. 2020-05-07 Richard Biener <rguenther@suse.de> PR middle-end/94703 * tree-core.h (tree_decl_common::gimple_reg_flag): Rename ... (tree_decl_common::not_gimple_reg_flag): ... to this. * tree.h (DECL_GIMPLE_REG_P): Rename ... (DECL_NOT_GIMPLE_REG_P): ... to this. * gimple-expr.c (copy_var_decl): Copy DECL_NOT_GIMPLE_REG_P. (create_tmp_reg): Simplify. (create_tmp_reg_fn): Likewise. (is_gimple_reg): Check DECL_NOT_GIMPLE_REG_P for all regs. * gimplify.c (create_tmp_from_val): Simplify. (gimplify_bind_expr): Likewise. (gimplify_compound_literal_expr): Likewise. (gimplify_function_tree): Likewise. (prepare_gimple_addressable): Set DECL_NOT_GIMPLE_REG_P. * asan.c (create_odr_indicator): Do not clear DECL_GIMPLE_REG_P. (asan_add_global): Copy it. * cgraphunit.c (cgraph_node::expand_thunk): Force args to be GIMPLE regs. * function.c (gimplify_parameters): Copy DECL_NOT_GIMPLE_REG_P. * ipa-param-manipulation.c (ipa_param_body_adjustments::common_initialization): Simplify. (ipa_param_body_adjustments::reset_debug_stmts): Copy DECL_NOT_GIMPLE_REG_P. * omp-low.c (lower_omp_for_scan): Do not set DECL_GIMPLE_REG_P. * sanopt.c (sanitize_rewrite_addressable_params): Likewise. * tree-cfg.c (make_blocks_1): Simplify. (verify_address): Do not verify DECL_GIMPLE_REG_P setting. * tree-eh.c (lower_eh_constructs_2): Simplify. * tree-inline.c (declare_return_variable): Adjust and generalize. (copy_decl_to_var): Copy DECL_NOT_GIMPLE_REG_P. (copy_result_decl_to_var): Likewise. * tree-into-ssa.c (pass_build_ssa::execute): Adjust comment. * tree-nested.c (create_tmp_var_for): Simplify. * tree-parloops.c (separate_decls_in_region_name): Copy DECL_NOT_GIMPLE_REG_P. * tree-sra.c (create_access_replacement): Adjust and generalize partial def support. * tree-ssa-forwprop.c (pass_forwprop::execute): Set DECL_NOT_GIMPLE_REG_P on decls we introduce partial defs on. * tree-ssa.c (maybe_optimize_var): Handle clearing of TREE_ADDRESSABLE and setting/clearing DECL_NOT_GIMPLE_REG_P independently. * lto-streamer-out.c (hash_tree): Hash DECL_NOT_GIMPLE_REG_P. * tree-streamer-out.c (pack_ts_decl_common_value_fields): Stream DECL_NOT_GIMPLE_REG_P. * tree-streamer-in.c (unpack_ts_decl_common_value_fields): Likewise. * cfgexpand.c (avoid_type_punning_on_regs): New. (discover_nonconstant_array_refs): Call avoid_type_punning_on_regs to avoid unsupported mode punning. lto/ * lto-common.c (compare_tree_sccs_1): Compare DECL_NOT_GIMPLE_REG_P. c/ * gimple-parser.c (c_parser_parse_ssa_name): Do not set DECL_GIMPLE_REG_P. cp/ * optimize.c (update_cloned_parm): Copy DECL_NOT_GIMPLE_REG_P. * gcc.dg/tree-ssa/pr94703.c: New testcase.
2020-05-06c++: ICE in value_dependent_expression_p in C++98 mode [PR94938]Marek Polacek2-3/+12
Here we ICE with -std=c++98 since the newly added call to uses_template_parms (r10-6357): we hit 26530 gcc_assert (cxx_dialect >= cxx11 26531 || INTEGRAL_OR_ENUMERATION_TYPE_P (type)); and TYPE is a record type. The problem is that the argument to value_dependent_expression_p does not satisfy potential_constant_expression which it must, as the comment explains. I thought about fixing this in uses_template_parms -- only call v_d_e_p if p_c_e is true, but in this case we want to also suppress the warnings if we don't have a constant expression. I couldn't simply check TREE_CONSTANT as in compute_array_index_type_loc, because then we'd stop warning in the new Wtype-limits3.C test. Fixed by using type_dependent_expression_p_push instead. This means that we won't suppress the warnings for value-dependent expressions that aren't type-dependent, e.g. sizeof (T). This only seems to make a difference for -Wdiv-by-zero, now tested in Wdiv-by-zero-3.C, where I think it's reasonable to warn. It could make -Wtautological-compare warn more, but that warning doesn't trigger when it gets constant arguments. Wtype-limits4.C is a test reduced from poly-int.h and it tests a scenario that was missing in our testsuite. This patch also moves the warning_sentinels after the RECURs -- we mean to use them for build_x_binary_op purposes only. PR c++/94938 * pt.c (tsubst_copy_and_build): Call type_dependent_expression_p_push instead of uses_template_parms. Move the warning_sentinels after the RECURs. * g++.dg/warn/Wdiv-by-zero-3.C: New test. * g++.dg/warn/Wtype-limits4.C: New test. * g++.dg/warn/template-2.C: New test. * g++.old-deja/g++.pt/crash10.C: Add dg-warning.
2020-05-06c++: Avoid strict_aliasing_warning on dependent types or expressions [PR94951]Jakub Jelinek2-6/+27
The following testcase gets a bogus warning during build_base_path, when cp_build_indirect_ref* calls strict_aliasing_warning with a dependent expression. IMHO calling get_alias_set etc. on dependent types feels wrong to me, we should just defer the warnings in those cases until instantiation and only handle the cases where neither type nor expr are dependent. 2020-05-06 Jakub Jelinek <jakub@redhat.com> PR c++/94951 * typeck.c (cp_strict_aliasing_warning): New function. (cp_build_indirect_ref_1, build_reinterpret_cast_1): Use it instead of strict_aliasing_warning. * g++.dg/warn/Wstrict-aliasing-bogus-tmpl.C: New test.
2020-05-06c++: Don't synthesize sfk_comparison method multiple times [PR94907]Jakub Jelinek2-1/+7
On the following testcase we ICE, because synthesize_method is called twice on the same sfk_comparison method fndecl, the first time it works fine because start_preparsed_function in that case sets both current_function_decl and cfun, but second time it is called it only sets the former and keeps cfun NULL, so we ICE when trying to store current_function_returns_value. I think it is just wrong to call synthesize_method multiple times, and most synthesize_method callers avoid that by not calling it if DECL_INITIAL is already set, so this patch does that too. 2020-05-06 Jakub Jelinek <jakub@redhat.com> PR c++/94907 * method.c (defaulted_late_check): Don't call synthesize_method on constexpr sfk_comparison if it has been called on it already. * g++.dg/cpp2a/spaceship-synth8.C: New test.
2020-05-06c++: QT overload regression with attribute [PR94946]Nathan Sidwell2-3/+12
Jason's fix for 90570 & 79585 was a bit overzealous. Dependent attribs should still attach to a parameter decl. * decl.c (grokdeclarator): Don't splice template attributes in parm context -- they can apply to the parm.
2020-05-06coroutines: Remove references to n4849 (NFC).Iain Sandoe2-14/+18
This just strips out references to the draft standard numbered n4849. The implementation is now intended to be applicable to the expected final version. gcc/cp/ChangeLog: 2020-05-05 Iain Sandoe <iain@sandoe.co.uk> * coroutines.cc: Remove references to n4849 throughout.
2020-05-05c++: CWG2235 partial ordering and non-dependent typesJason Merrill2-9/+6
Issue 2235 removed the rule previously added for issues 1391/1847 that had partial ordering completely ignore function parameters with no deducible template parameters. gcc/cp/ChangeLog 2020-05-05 Jason Merrill <jason@redhat.com> CWG 2235 * pt.c (more_specialized_fn): Do consider parms with no deducible template parameters.
2020-05-05c++: constexpr and lambda capture [PR90212]Jason Merrill2-1/+13
This is the same issue as PR86429, just in potential_constant_expression_1 rather than cxx_eval_constant_expression. As in that case, when we're trying to evaluate a constant expression within a lambda, we don't have a constant closure object to refer to, but we can try to refer directly to the captured variable. gcc/cp/ChangeLog 2020-05-05 Jason Merrill <jason@redhat.com> PR c++/90212 * constexpr.c (potential_constant_expression_1): In a lambda function, consider a captured variable directly.
2020-05-05coroutines: Replace extra checks for co_yield with asserts.Iain Sandoe2-9/+18
The lowering of co_yield to a promise method call and a co_await was moved to the initial analysis phase with the intention of avoiding the need to handle the two cases later. Before removing the later checks entirely, this patch replaces them with checking asserts. gcc/cp/Changelog: 2020-05-05 Iain Sandoe <iain@sandoe.co.uk> * coroutines.cc (transform_await_wrapper): Check that we have no unlowered co_yields. (captures_temporary): Likewise. (register_awaits): Likewise.
2020-05-05c++: Avoid inconsistency in lambda fn's this pointer name [pr94807]Nathan Sidwell3-3/+10
* coroutines.cc (morph_fn_to_coro): Just check for closure_identifier. * pt.c (tsubst_function_decl): Update lambda fn's this_ptr name.
2020-05-05c++: Member template function lookup failure [PR94799]Marek Polacek2-9/+29
Whew, this took a while. We fail to parse "p->template A<T>::a()" (where p is of type A<T> *) because since r249752 we treat the RHS of the -> as dependent and avoid a lookup in the enclosing context: since that rev cp_parser_template_name checks parser->context->object_type too, which here is unknown_type_node, signalling a type-dependent object: 7756 if (dependent_p) 7757 /* Tell cp_parser_lookup_name that there was an object, even though it's 7758 type-dependent. */ 7759 parser->context->object_type = unknown_type_node; with which cp_parser_template_name returns identifier 'A', cp_parser_class_name then creates a TEMPLATE_ID_EXPR A<T>, but then 23735 decl = make_typename_type (scope, decl, tag_type, tf_error); in cp_parser_class_name fails because scope is NULL. Then we return error_mark_node and parse errors ensue. I've tried various approaches, e.g. keeping TEMPLATE_ID_EXPR around instead of calling make_typename_type, which didn't work, whereupon I realized that since we don't want to perform name lookup if we've seen the template keyword and the scope is dependent, we can adjust parser->context->object_type and use the type of the object expression as the scope, even if it's type-dependent. This should be in line with [basic.lookup.classref]p4. If the postfix expression doesn't have a type, use typeof to carry its type. This typeof will be processed in tsubst/TYPENAME_TYPE. PR c++/94799 * parser.c (cp_parser_postfix_dot_deref_expression): If we have a type-dependent object of class type, stash it to parser->context->object_type. If the postfix expression doesn't have a type, use typeof. (cp_parser_class_name): Consider object scope too. (cp_parser_lookup_name): Remove code dealing with the case when object_type is unknown_type_node. * g++.dg/lookup/this1.C: Adjust dg-error. * g++.dg/template/lookup12.C: New test. * g++.dg/template/lookup13.C: New test. * g++.dg/template/lookup14.C: New test. * g++.dg/template/lookup15.C: New test.
2020-05-04c++: Avoid unnecessary copying in cp_fold [PR94038]Patrick Palka2-23/+26
When folding a CALL_EXPR, we can avoid copying it until folding changes one of its arguments. And when folding a TREE_VEC, we can avoid using an intermediate releasing_vec by copying the TREE_VEC as soon as folding changes one of its arguments, like we do in the CALL_EXPR case. Incidentally, the CALL_EXPR change also fixes the testcase in PR94038. The reason is that the call to maybe_constant_value from cp_fold on the call 'bar<int>()' now reuses the result of the earlier call to maybe_constant_value from fold_for_warn, via the cv_cache. This earlier call passes uid_sensitive=true, whereas the call from cp_fold passes uid_sensitive=false, and so by reusing the cached result of the earlier call we now avoid instantiating bar<int> at all. gcc/cp/ChangeLog: PR c++/94038 * cp-gimplify.c (cp_fold) <case CALL_EXPR>: Move some variable declarations closer to their uses. Copy the CALL_EXPR only when one of its arguments has changed. <case TREE_VEC>: Instead of first collecting the folded arguments into a releasing_vec, just make a copy of the TREE_VEC as soon as folding changes one of its arguments. gcc/testsuite/ChangeLog: PR c++/94038 * g++.dg/warn/pr94038.C: New test.
2020-05-04coroutines: Mark the gro as artificial.Iain Sandoe2-0/+7
This corrects an oversight, the coro.gro object is a a compiler-generated entity and should be marked as artificial and ignored. gcc/cp/ChangeLog: 2020-05-04 Iain Sandoe <iain@sandoe.co.uk> * coroutines.cc (morph_fn_to_coro): Mark the coro.gro variable as artificial and ignored.
2020-05-04c++: Simplify process_template_parmNathan Sidwell2-21/+31
Process_template_parm ends up walking the parameter list twice. There's not need to do this. Just rember the final node and modify its CHAIN directly. Also comment on why end_template_parm_list does a pop and a push, rather than modifying the header in place. pt.c (process_template_parm): Don't walk the template list twice, remember the final node instead. (end_template_parm_list): Refactor. Comment on why we do a pop and a push.