Skip to content
Snippets Groups Projects
  1. Jan 02, 2022
    • Jason Merrill's avatar
      c++: don't wrap cleanups that can't throw · 092e60f5
      Jason Merrill authored
      Since C++11, the vast majority of destructors are noexcept, so
      wrap_temporary_cleanups adds a bunch of useless TRY_CATCH_EXPR to be removed
      later in the optimizers.  It's simple to avoid adding them in the first
      place.
      
      gcc/cp/ChangeLog:
      
      	* decl.c (wrap_cleanups_r): Don't wrap if noexcept.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/eh/cleanup6.C: New test.
      092e60f5
  2. Dec 21, 2021
  3. Dec 20, 2021
    • Patrick Palka's avatar
      c++: memfn lookup consistency in incomplete-class ctx · ab85331c
      Patrick Palka authored
      When instantiating a call to a member function of a class template, we
      repeat the member function lookup in order to obtain the corresponding
      partially instantiated functions.  Within an incomplete-class context
      however, we need to be more careful when repeating the lookup because we
      don't want to introduce later-declared member functions that weren't
      visible at template definition time.  We're currently not careful enough
      in this respect, which causes us to reject memfn1.C below.
      
      This patch fixes this issue by making tsubst_baselink filter out from
      the instantiation-time lookup those member functions that were invisible
      at template definition time.  This is really only necessary within an
      incomplete-class context, so this patch adds a heuristic flag to BASELINK
      to help us avoid needlessly performing this filtering step (which would
      be a no-op) in complete-class contexts.
      
      This is also necessary for the ahead-of-time overload set pruning
      implemented in r12-6075 to be effective for member functions within
      class templates.
      
      gcc/cp/ChangeLog:
      
      	* call.c (build_new_method_call): Set
      	BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P on the pruned baselink.
      	* cp-tree.h (BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P): Define.
      	* pt.c (filter_memfn_lookup): New subroutine of tsubst_baselink.
      	(tsubst_baselink): Use filter_memfn_lookup on the new lookup
      	result when BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P is set on the
      	old baselink.  Remove redundant BASELINK_P check.
      	* search.c (build_baselink): Set
      	BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P appropriately.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/lookup/memfn1.C: New test.
      	* g++.dg/template/non-dependent16b.C: New test.
      ab85331c
    • Patrick Palka's avatar
      c++: ahead-of-time overload set pruning for non-dep calls · 2decd2ca
      Patrick Palka authored
      This patch makes us remember the function selected by overload resolution
      during ahead of time processing of a non-dependent call expression, so
      that at instantiation time we avoid repeating some of the work of overload
      resolution for the call.  Note that we already do this for non-dependent
      operator expressions via build_min_non_dep_op_overload.
      
      Some caveats:
      
       * When processing ahead of time a non-dependent call to a member
         function template of a currently open class template (as in
         g++.dg/template/deduce4.C), we end up generating an "inside-out"
         partial instantiation such as S<T>::foo<int, int>(), the likes of
         which we're apparently not prepared to fully instantiate.  So in this
         situation, we instead prune to the selected template instead of the
         specialization in this situation.
      
       * This change triggered a latent FUNCTION_DECL pretty printing issue
         in cpp0x/error2.C -- since we now resolve the call to foo<0> ahead
         of time, the error now looks like:
      
           error: expansion pattern ‘foo()()=0’ contains no parameter pack
      
         where the FUNCTION_DECL for foo<0> is clearly misprinted.  But this
         pretty-printing issue could be reproduced without this patch if
         we define foo as a non-template function.  Since this testcase was
         added to verify pretty printing of TEMPLATE_ID_EXPR, I work around
         this test failure by making the call to foo type-dependent and thus
         immune to this ahead of time pruning.
      
       * We now reject parts of cpp0x/fntmp-equiv1.C because we notice that
         the non-dependent call d(f, b) in
      
           int d(int, int);
           template <unsigned long f, unsigned b, typename> e<d(f, b)> d();
      
         is non-constexpr.  Since this testcase is about equivalency of
         dependent names in the context of declaration matching, it seems the
         best fix here is to make the calls to d, d2 and d3 within the
         function signatures dependent.
      
      gcc/cp/ChangeLog:
      
      	* call.c (build_new_method_call): For a non-dependent call
      	expression inside a template, returning a templated tree
      	whose overload set contains just the selected function.
      	* semantics.c (finish_call_expr): Likewise.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp0x/error2.C: Make the call to foo type-dependent in
      	order to avoid latent pretty-printing issue for FUNCTION_DECL
      	inside MODOP_EXPR.
      	* g++.dg/cpp0x/fntmp-equiv1.C: Make the calls to d, d2 and d3
      	within the function signatures dependent.
      	* g++.dg/template/non-dependent16.C: New test.
      	* g++.dg/template/non-dependent16a.C: New test.
      	* g++.dg/template/non-dependent17.C: New test.
      2decd2ca
    • GCC Administrator's avatar
      Daily bump. · 29309f6e
      GCC Administrator authored
      29309f6e
  4. Dec 19, 2021
    • Matthias Kretz's avatar
      c++: don't ICE on NAMESPACE_DECL inside FUNCTION_DECL · 6bcb6ed5
      Matthias Kretz authored
      
      Code like
        void swap() {
          namespace __variant = __detail::__variant;
          ...
        }
      create a NAMESPACE_DECL where the CP_DECL_CONTEXT is a FUNCTION_DECL.
      DECL_TEMPLATE_INFO fails on NAMESPACE_DECL and therefore must be handled
      first in the assertion.
      
      Signed-off-by: default avatarMatthias Kretz <m.kretz@gsi.de>
      
      gcc/cp/ChangeLog:
      
      	* module.cc (trees_out::get_merge_kind): NAMESPACE_DECLs also
      	cannot have a DECL_TEMPLATE_INFO.
      6bcb6ed5
    • Patrick Palka's avatar
      c++: nested lambda capturing a capture proxy, cont [PR94376] · 89cf57ea
      Patrick Palka authored
      The r12-5403 fix apparently doesn't handle the case where the inner
      lambda explicitly rather than implicitly captures the capture proxy from
      the outer lambda, which causes us to reject the first example in the
      testcase below.
      
      This is because compared to an implicit capture, the effective initializer
      for an explicit capture is wrapped in a location wrapper (pointing to within
      the capture list), and this wrapper foils the is_capture_proxy check added
      in r12-5403.
      
      The simplest fix appears to be to strip location wrappers accordingly
      before checking is_capture_proxy.  And to help prevent against this kind
      of bug, this patch also makes is_capture_proxy assert it doesn't see a
      location wrapper.
      
      	PR c++/94376
      
      gcc/cp/ChangeLog:
      
      	* lambda.c (lambda_capture_field_type): Strip location wrappers
      	before checking for a capture proxy.
      	(is_capture_proxy): Assert that we don't see a location wrapper.
      	(mark_const_cap_r): Don't call is_constant_capture_proxy on a
      	location wrapper.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp0x/lambda/lambda-nested9a.C: New test.
      89cf57ea
    • Patrick Palka's avatar
      c++: local_specializations and recursive constrained fn [PR103714] · 30c286aa
      Patrick Palka authored
      Here during constraint checking for the inner call to A<0>::f<0>,
      substitution into the PARM_DECL d in the atomic constraint yields the
      wrong local specialization because local_specializations at this point
      is nonempty, and contains specializations for the caller A<0>::f<1>.
      
      This patch makes us call push_to_top_level during satisfaction, which'll
      temporarily clear local_specializations for us.
      
      	PR c++/103714
      
      gcc/cp/ChangeLog:
      
      	* constraint.cc (satisfy_declaration_constraints): Do
      	push_to_top_level and pop_from_top_level around the call to
      	satisfy_normalized_constraints.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp2a/concepts-uneval5.C: New test.
      30c286aa
  5. Dec 18, 2021
  6. Dec 17, 2021
    • Marek Polacek's avatar
      attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] · 6afb8a68
      Marek Polacek authored
      My patch to implement -Wno-attribute=A::b caused a bogus error when
      parsing
      
        [[foo::bar(1, 2)]];
      
      when -Wno-attributes=foo::bar was specified on the command line, because
      when we create a fake foo::bar attribute and insert it into our attribute
      table, it is created with max_length == 0 which doesn't allow any args.
      That is wrong -- we know nothing about the attribute, so we shouldn't
      require any specific number of arguments.  And since unknown attributes
      can be rather complex (see for example omp::{directive,sequence}), we
      must skip parsing their arguments.  To that end, I'm using max_length
      with value -2.
      
      Also let's not warn about things like
      
        [[vendor::assume(true)]];
      
      because they may have some meaning (this is reminiscent of C++ Portable
      Assumptions).
      
      	PR c/103649
      
      gcc/ChangeLog:
      
      	* attribs.c (handle_ignored_attributes_option): Create the fake
      	attribute with max_length == -2.
      	(attribute_ignored_p): New overloads.
      	* attribs.h (attribute_ignored_p): Declare them.
      	* tree-core.h (struct attribute_spec): Document that max_length
      	can be -2.
      
      gcc/c/ChangeLog:
      
      	* c-decl.c (c_warn_unused_attributes): Don't warn for
      	attribute_ignored_p.
      	* c-parser.c (c_parser_std_attribute): Skip parsing of the attribute
      	arguments when the attribute is ignored.
      
      gcc/cp/ChangeLog:
      
      	* parser.c (cp_parser_declaration): Don't warn for attribute_ignored_p.
      	(cp_parser_std_attribute): Skip parsing of the attribute
      	arguments when the attribute is ignored.
      
      gcc/testsuite/ChangeLog:
      
      	* c-c++-common/Wno-attributes-6.c: New test.
      6afb8a68
    • Marek Polacek's avatar
      c++: Improve diagnostic for class tmpl/class redecl [PR103749] · fae01686
      Marek Polacek authored
      For code like
      
        template<typename>
        struct bar;
      
        struct bar {
          int baz;
        };
      
        bar var;
      
      we emit a fairly misleading and unwieldy diagnostic:
      
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      $ g++ -c u.cc
      u.cc:6:8: error: template argument required for 'struct bar'
          6 | struct bar {
            |        ^~~
      u.cc:10:5: error: class template argument deduction failed:
         10 | bar var;
            |     ^~~
      u.cc:10:5: error: no matching function for call to 'bar()'
      u.cc:3:17: note: candidate: 'template<class> bar()-> bar< <template-parameter-1-1> >'
          3 |   friend struct bar;
            |                 ^~~
      u.cc:3:17: note:   template argument deduction/substitution failed:
      u.cc:10:5: note:   couldn't deduce template parameter '<template-parameter-1-1>'
         10 | bar var;
            |     ^~~
      u.cc:3:17: note: candidate: 'template<class> bar(bar< <template-parameter-1-1> >)-> bar< <template-parameter-1-1> >'
          3 |   friend struct bar;
            |                 ^~~
      u.cc:3:17: note:   template argument deduction/substitution failed:
      u.cc:10:5: note:   candidate expects 1 argument, 0 provided
         10 | bar var;
            |     ^~~
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      but with this patch we get:
      
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      z.C:4:10: error: class template 'bar' redeclared as non-template
          4 |   struct bar {
            |          ^~~
      z.C:2:10: note: previous declaration here
          2 |   struct bar;
            |          ^~~
      z.C:8:7: error: 'bar<...auto...> var' has incomplete type
          8 |   bar var;
            |       ^~~
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      which is clearer about what the problem is.
      
      I thought it'd be nice to avoid printing the messages about failed CTAD,
      too.  To that end, I'm using CLASSTYPE_ERRONEOUS to suppress CTAD.  Not
      sure if that's entirely kosher.
      
      The other direction (first a non-template class declaration followed by
      a class template definition) we handle quite well:
      
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      z.C:11:8: error: 'bar' is not a template
         11 | struct bar {};
            |        ^~~
      z.C:8:8: note: previous declaration here
          8 | struct bar;
            |        ^~~
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      	PR c++/103749
      
      gcc/cp/ChangeLog:
      
      	* decl.c (lookup_and_check_tag): Give an error when a class was
      	declared as template but no template header has been provided.
      	* pt.c (do_class_deduction): Don't deduce CLASSTYPE_ERRONEOUS
      	types.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/template/redecl4.C: Adjust dg-error.
      	* g++.dg/diagnostic/redeclaration-2.C: New test.
      fae01686
    • Iain Sandoe's avatar
      coroutines: Handle initial awaiters with non-void returns [PR 100127]. · 2466a8d0
      Iain Sandoe authored
      
      The way in which a C++20 coroutine is specified discards any value
      that might be returned from the initial or final await expressions.
      
      This ICE was caused by an initial await expression with an
      await_resume () returning a reference, the function rewrite code
      was not set up to expect this.
      
      Fixed by looking through any indirection present and by explicitly
      discarding the value, if any, returned by await_resume().
      
      It does not seem useful to make a diagnostic for this, since
      the user could define a generic awaiter that usefully returns
      values when used in a different position from the initial (or
      final) await expressions.
      
      Signed-off-by: default avatarIain Sandoe <iain@sandoe.co.uk>
      
      	PR c++/100127
      
      gcc/cp/ChangeLog:
      
      	* coroutines.cc (coro_rewrite_function_body): Handle initial
      	await expressions that try to produce a reference value.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/coroutines/pr100127.C: New test.
      2466a8d0
    • Iain Sandoe's avatar
      coroutines: Pass lvalues to user-defined operator new [PR 100772]. · 921942a8
      Iain Sandoe authored
      
      The wording of the standard has been clarified to be explicit that
      the the parameters to any user-defined operator-new in the promise
      class should be lvalues.
      
      Signed-off-by: default avatarIain Sandoe <iain@sandoe.co.uk>
      
      	PR c++/100772
      
      gcc/cp/ChangeLog:
      
      	* coroutines.cc (morph_fn_to_coro): Convert function parms
      	from reference before constructing any operator-new args
      	list.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/coroutines/pr100772-a.C: New test.
      	* g++.dg/coroutines/pr100772-b.C: New test.
      921942a8
    • Jason Merrill's avatar
      c++: tweak comment · 871504b0
      Jason Merrill authored
      The comment documented a parameter that no longer exists.
      
      gcc/cp/ChangeLog:
      
      	* constraint.cc (deduce_concept_introduction): Adjust comment.
      871504b0
    • Jason Merrill's avatar
      c++: layout of aggregate base with DMI [PR103681] · a37e8ce3
      Jason Merrill authored
      C++14 changed the definition of 'aggregate' to allow default member
      initializers, but such classes still need to be considered "non-POD for the
      purpose of layout" for ABI compatibility with C++11 code.  It seems rare to
      derive from such a class, as evidenced by how long this bug has
      survived (since r216750 in 2014), but it's certainly worth fixing.
      
      We only warn when we were failing to allocate another field into the
      tail padding of the newly aggregate class; this is the only ABI impact.
      
      This also changes end_of_class to consider all data members, not just empty
      data members; that used to be an additional flag, removed in r9-5710, but I
      don't see any reason not to always include them.  This makes the result of
      the function correspond to the ABI nvsize term and its nameless counterpart
      that does include virtual bases.
      
      When looking closely at other users of end_of_class, I realized that we were
      assuming that the latter corresponded to the ABI dsize term, but it doesn't
      if the class ends with an empty virtual base (in the rare case that the
      empty base can't be assigned offset 0), and this matters for layout of
      [[no_unique_address]].  So I added another mode that returns the desired
      value for that case.  I'm not adding a warning for this ABI fix because it's
      a C++20 feature.
      
      	PR c++/103681
      
      gcc/ChangeLog:
      
      	* common.opt (fabi-version): Add v17.
      
      gcc/cp/ChangeLog:
      
      	* cp-tree.h (struct lang_type): Add non_pod_aggregate.
      	(CLASSTYPE_NON_POD_AGGREGATE): New.
      	* class.c (check_field_decls): Set it.
      	(check_bases_and_members): Check it.
      	(check_non_pod_aggregate): New.
      	(enum eoc_mode): New.
      	(end_of_class): Always include non-empty fields.
      	Add eoc_nv_or_dsize mode.
      	(include_empty_classes, layout_class_type): Adjust.
      
      gcc/c-family/ChangeLog:
      
      	* c-opts.c (c_common_post_options): Update defaults.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/abi/macro0.C: Update value.
      	* g++.dg/abi/no_unique_address6.C: New test.
      	* g++.dg/abi/nsdmi-aggr1.C: New test.
      	* g++.dg/abi/nsdmi-aggr1a.C: New test.
      a37e8ce3
    • GCC Administrator's avatar
      Daily bump. · 774269aa
      GCC Administrator authored
      774269aa
  7. Dec 16, 2021
    • Marek Polacek's avatar
      c++: delayed noexcept in member function template [PR99980] · 06041b2c
      Marek Polacek authored
      Some time ago I noticed that we don't properly delay parsing of
      noexcept for member function templates.  This patch fixes that.
      
      It didn't work because even though we set CP_PARSER_FLAGS_DELAY_NOEXCEPT
      in cp_parser_member_declaration, member template declarations take
      a different path: we call cp_parser_template_declaration and return
      prior to setting the flag.
      
      	PR c++/99980
      
      gcc/cp/ChangeLog:
      
      	* parser.c (cp_parser_single_declaration): Maybe pass
      	CP_PARSER_FLAGS_DELAY_NOEXCEPT down to cp_parser_init_declarator.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp0x/noexcept71.C: New test.
      06041b2c
    • Martin Sebor's avatar
      Check for class type before assuming a type is one [PR103703]. · 93faac7e
      Martin Sebor authored
      Resolves:
      PR c++/103703 - ICE with -Wmismatched-tags with friends and templates
      
      gcc/cp/ChangeLog:
      
      	PR c++/103703
      	* parser.c (class_decl_loc_t::diag_mismatched_tags): Check for class
      	type before assuming a type is one.
      
      gcc/testsuite/ChangeLog:
      
      	PR c++/103703
      	* g++.dg/warn/Wmismatched-tags-9.C: New test.
      93faac7e
    • Patrick Palka's avatar
      c++: two-stage name lookup for overloaded operators [PR51577] · bb2a7f80
      Patrick Palka authored
      In order to properly implement two-stage name lookup for dependent
      operator expressions, we need to remember the result of unqualified
      lookup of the operator at template definition time, and reuse that
      result rather than performing another unqualified lookup at
      instantiation time.
      
      Ideally we could just store the lookup in the expression directly, but
      as pointed out in r9-6405 this isn't really possible since we use the
      standard tree codes to represent most dependent operator expressions.
      
      We could perhaps create a new tree code to represent dependent operator
      expressions, with enough operands to store the lookup along with
      everything else, but that'd require a lot of careful work to make sure
      we handle this new tree code properly across the frontend.
      
      But currently type-dependent operator (and call) expressions are given
      an empty TREE_TYPE, which dependent_type_p treats as dependent, so this
      field is effectively unused except to signal that the expression is
      type-dependent.  It'd be convenient if we could store the lookup there
      while preserving the dependent-ness of the expression.
      
      To that end, this patch creates a new kind of type, called
      DEPENDENT_OPERATOR_TYPE, which we give to dependent operator expressions
      and into which we can store the result of operator lookup at template
      definition time (DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS).  Since this
      type is always dependent (by definition), and since the frontend doesn't
      seem to care much about the exact type of a type-dependent expression,
      using this type in place of a NULL_TREE type seems to "just work"; only
      dependent_type_p and WILDCARD_TYPE_P need to be adjusted to return true
      for this new type.
      
      The rest of the patch mostly consists of adding the necessary plumbing
      to pass DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS to add_operator_candidates,
      adjusting all callers of build_x_* appropriately, and removing the now
      unnecessary push_operator_bindings mechanism.
      
      In passing, this patch simplifies finish_constraint_binary_op to avoid
      using build_x_binary_op for building a binary constraint-expr; we don't
      need to consider operator overloads here, as the &&/|| inside a
      constraint effectively always has the built-in meaning (since atomic
      constraints must have bool type).
      
      This patch also makes FOLD_EXPR_OP yield a tree_code instead of a raw
      INTEGER_CST.
      
      Finally, this patch adds the XFAILed test operator-8.C which is about
      broken two-stage name lookup for rewritten non-dependent operator
      expressions, an existing bug that's otherwise only documented in
      build_new_op.
      
      	PR c++/51577
      	PR c++/83035
      	PR c++/100465
      
      gcc/cp/ChangeLog:
      
      	* call.c (add_operator_candidates): Add lookups parameter.
      	Use it to avoid performing a second unqualified lookup when
      	instantiating a dependent operator expression.
      	(build_new_op): Add lookups parameter and pass it appropriately.
      	* constraint.cc (finish_constraint_binary_op): Use
      	build_min_nt_loc instead of build_x_binary_op.
      	* coroutines.cc (build_co_await): Adjust call to build_new_op.
      	* cp-objcp-common.c (cp_common_init_ts): Mark
      	DEPENDENT_OPERATOR_TYPE appropriately.
      	* cp-tree.def (DEPENDENT_OPERATOR_TYPE): Define.
      	* cp-tree.h (WILDCARD_TYPE_P): Accept DEPENDENT_OPERATOR_TYPE.
      	(FOLD_EXPR_OP_RAW): New, renamed from ...
      	(FOLD_EXPR_OP): ... this.  Change this to return the tree_code directly.
      	(DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS): Define.
      	(templated_operator_saved_lookups): Define.
      	(build_new_op): Add lookups parameter.
      	(build_dependent_operator_type): Declare.
      	(build_x_indirect_ref): Add lookups parameter.
      	(build_x_binary_op): Likewise.
      	(build_x_unary_op): Likewise.
      	(build_x_compound_expr): Likewise.
      	(build_x_modify_expr): Likewise.
      	* cxx-pretty-print.c (get_fold_operator): Adjust after
      	FOLD_EXPR_OP change.
      	* decl.c (start_preparsed_function): Don't call
      	push_operator_bindings.
      	* decl2.c (grok_array_decl): Adjust calls to build_new_op.
      	* method.c (do_one_comp): Likewise.
      	(build_comparison_op): Likewise.
      	* module.cc (trees_out::type_node): Handle DEPENDENT_OPERATOR_TYPE.
      	(trees_in::tree_node): Likewise.
      	* name-lookup.c (lookup_name): Revert r11-2876 change.
      	(op_unqualified_lookup): Remove.
      	(maybe_save_operator_binding): Remove.
      	(discard_operator_bindings): Remove.
      	(push_operator_bindings): Remove.
      	* name-lookup.h (maybe_save_operator_binding): Remove.
      	(push_operator_bindings): Remove.
      	(discard_operator_bindings): Remove.
      	* parser.c (cp_parser_unary_expression): Adjust calls to build_x_*.
      	(cp_parser_binary_expression): Likewise.
      	(cp_parser_assignment_expression): Likewise.
      	(cp_parser_expression): Likewise.
      	(do_range_for_auto_deduction): Likewise.
      	(cp_convert_range_for): Likewise.
      	(cp_parser_perform_range_for_lookup): Likewise.
      	(cp_parser_template_argument): Likewise.
      	(cp_parser_omp_for_cond): Likewise.
      	(cp_parser_omp_for_incr): Likewise.
      	(cp_parser_omp_for_loop_init): Likewise.
      	(cp_convert_omp_range_for): Likewise.
      	(cp_finish_omp_range_for): Likewise.
      	* pt.c (fold_expression): Adjust after FOLD_EXPR_OP change. Pass
      	templated_operator_saved_lookups to build_x_*.
      	(tsubst_omp_for_iterator): Adjust call to build_x_modify_expr.
      	(tsubst_expr) <case COMPOUND_EXPR>: Pass
      	templated_operator_saved_lookups to build_x_*.
      	(tsubst_copy_and_build) <case INDIRECT_REF>: Likewise.
      	<case tcc_unary>: Likewise.
      	<case tcc_binary>: Likewise.
      	<case MODOP_EXPR>: Likewise.
      	<case COMPOUND_EXPR>: Likewise.
      	(dependent_type_p_r): Return true for DEPENDENT_OPERATOR_TYPE.
      	* ptree.c (cxx_print_type): Handle DEPENDENT_OPERATOR_TYPE.
      	* semantics.c (finish_increment_expr): Adjust call to
      	build_x_unary_op.
      	(finish_unary_op_expr): Likewise.
      	(handle_omp_for_class_iterator): Adjust calls to build_x_*.
      	(finish_omp_cancel): Likewise.
      	(finish_unary_fold_expr): Use build_dependent_operator_type.
      	(finish_binary_fold_expr): Likewise.
      	* tree.c (cp_free_lang_data): Don't call discard_operator_bindings.
      	* typeck.c (rationalize_conditional_expr): Adjust call to
      	build_x_binary_op.
      	(op_unqualified_lookup): Define.
      	(build_dependent_operator_type): Define.
      	(build_x_indirect_ref): Add lookups parameter and use
      	build_dependent_operator_type.
      	(build_x_binary_op): Likewise.
      	(build_x_array_ref): Likewise.
      	(build_x_unary_op): Likewise.
      	(build_x_compound_expr_from_list): Adjust call to
      	build_x_compound_expr.
      	(build_x_compound_expr_from_vec): Likewise.
      	(build_x_compound_expr): Add lookups parameter and use
      	build_dependent_operator_type.
      	(cp_build_modify_expr): Adjust call to build_new_op.
      	(build_x_modify_expr): Add lookups parameter and use
      	build_dependent_operator_type.
      	* typeck2.c (build_x_arrow): Adjust call to build_new_op.
      
      libcc1/ChangeLog:
      
      	* libcp1plugin.cc (plugin_build_unary_expr): Adjust call to
      	build_x_unary_op.
      	(plugin_build_binary_expr): Adjust call to build_x_binary_op.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/lookup/operator-3.C: Split out operator overload
      	declarations into ...
      	* g++.dg/lookup/operator-3-ops.h: ... here.
      	* g++.dg/lookup/operator-3a.C: New test.
      	* g++.dg/lookup/operator-4.C: New test.
      	* g++.dg/lookup/operator-4a.C: New test.
      	* g++.dg/lookup/operator-5.C: New test.
      	* g++.dg/lookup/operator-5a.C: New test.
      	* g++.dg/lookup/operator-6.C: New test.
      	* g++.dg/lookup/operator-7.C: New test.
      	* g++.dg/lookup/operator-8.C: New test.
      bb2a7f80
    • GCC Administrator's avatar
      Daily bump. · 8a89c39b
      GCC Administrator authored
      8a89c39b
  8. Dec 15, 2021
    • Marek Polacek's avatar
      c++: Allow constexpr decltype(auto) [PR102229] · 06d5dcef
      Marek Polacek authored
      My r11-2202 was trying to enforce [dcl.type.auto.deduct]/4, which says
      "If the placeholder-type-specifier is of the form type-constraint[opt]
      decltype(auto), T shall be the placeholder alone."  But this made us
      reject 'constexpr decltype(auto)', which, after clarification from CWG,
      should be valid.  [dcl.type.auto.deduct]/4 is supposed to be a syntactic
      constraint, not semantic, so it's OK that the constexpr marks the object
      as const.
      
      As a consequence, checking TYPE_QUALS in do_auto_deduction is too late,
      and we have a FIXME there anyway.  So in this patch I'm attempting to
      detect 'const decltype(auto)' earlier.  If I'm going to use TYPE_QUALS,
      it needs to happen before we mark the object as const due to constexpr,
      that is, before grokdeclarator's
      
        /* A `constexpr' specifier used in an object declaration declares
           the object as `const'.  */
        if (constexpr_p && innermost_code != cdk_function)
          ...
      
      Constrained decltype(auto) was a little problem, hence the TYPENAME
      check.  But in a typename context you can't use decltype(auto) anyway,
      I think.
      
      	PR c++/102229
      
      gcc/cp/ChangeLog:
      
      	* decl.c (check_decltype_auto): New.
      	(grokdeclarator): Call it.
      	* pt.c (do_auto_deduction): Don't check decltype(auto) here.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp1y/decltype-auto5.C: New test.
      06d5dcef
    • Martin Liska's avatar
      c++: Fix warning word splitting [PR103713] · 7527ddec
      Martin Liska authored
      	PR c++/103713
      
      gcc/cp/ChangeLog:
      
      	* tree.c (maybe_warn_parm_abi): Fix warning word splitting.
      7527ddec
    • Jakub Jelinek's avatar
      openmp: Avoid calling operand_equal_p on OMP_CLAUSEs [PR103704] · c0e34451
      Jakub Jelinek authored
      On OMP_CLAUSEs we reuse TREE_TYPE as CP_OMP_CLAUSE_INFO in the C++ FE.
      This confuses the hashing code that operand_equal_p does when checking.
      There is really no reason to compare OMP_CLAUSEs against expressions
      like captured this, they will never compare equal.
      
      2021-12-15  Jakub Jelinek  <jakub@redhat.com>
      
      	PR c++/103704
      	* semantics.c (finish_omp_target_clauses_r): For OMP_CLAUSEs
      	just walk subtrees.
      
      	* g++.dg/gomp/pr103704.C: New test.
      c0e34451
    • GCC Administrator's avatar
      Daily bump. · 9c6586bc
      GCC Administrator authored
      9c6586bc
  9. Dec 14, 2021
    • Patrick Palka's avatar
      c++: processing_template_decl vs template depth [PR103408] · 561414cd
      Patrick Palka authored
      We use processing_template_decl in two slightly different ways: as a
      flag to signal that we're dealing with templated trees, and as a measure
      of the current syntactic template nesting depth.  This overloaded
      meaning of p_t_d is conceptually confusing and leads to bugs that we end
      up working around in an ad-hoc fashion.
      
      This patch replaces all uses of processing_template_decl that care about
      its magnitude to instead look at the depth of current_template_parms
      via a new macro current_template_depth.  This allows us to eliminate 3
      workarounds in the concepts code: two about non-templated
      requires-expressions (in constraint.cc) and one about lambdas inside
      constraints (in cp_parser_requires_clause_expression etc).  This also
      fixes the testcase in PR103408 about auto(x) used inside a non-templated
      requires-expression.
      
      The replacement was mostly mechanical, aside from two issues:
      
        * In synthesize_implicit_template_parm, when introducing a new template
          parameter list for an abbreviated function template, we need to add
          the new level of current_template_parms sooner, before calling
          process_template_parm, since this latter function now looks at
          current_template_depth to determine the level of the new parameter.
      
        * In instantiate_class_template_1 after substituting a template
          friend declaration, we currently increment processing_template_decl
          around the call to make_friend_class so that the friend_depth
          computation within this subroutine yields a nonzero value.  We could
          just replace this with an equivalent manipulation of
          current_template_depth, but this patch instead rewrites the
          friend_depth calculation within make_friend_class to not depend on
          p_t_d / c_t_d at all when called from instantiate_class_template_1.
      
      	PR c++/103408
      
      gcc/cp/ChangeLog:
      
      	* constraint.cc (type_deducible_p): Remove workaround for
      	non-templated requires-expressions.
      	(normalize_placeholder_type_constraints): Likewise.
      	* cp-tree.h (current_template_depth): Define.
      	(PROCESSING_REAL_TEMPLATE_DECL): Inspect current_template_depth
      	instead of the magnitude of processing_template_decl.
      	* decl.c (start_decl): Likewise.
      	(grokfndecl): Likewise.
      	(grokvardecl): Likewise.
      	(grokdeclarator): Likewise.
      	* friend.c (make_friend_class): Likewise.  Calculate
      	friend_depth differently when called at instantiation time
      	instead of parse time.
      	(do_friend): Likewise.
      	* parser.c (cp_parser_requires_clause_expression): Remove
      	workaround for lambdas inside constraints.
      	(cp_parser_constraint_expression): Likewise.
      	(cp_parser_requires_expression): Likewise.
      	(synthesize_implicit_template_parm): Add to current_template_parms
      	before calling process_template_parm.
      	* pt.c (inline_needs_template_parms): Inspect
      	current_template_depth instead of the magnitude of
      	processing_template_decl.
      	(push_inline_template_parms_recursive): Likewise.
      	(maybe_begin_member_template_processing): Likewise.
      	(begin_template_parm_list): Likewise.
      	(process_template_parm): Likewise.
      	(end_template_parm_list): Likewise.
      	(push_template_decl): Likewise.
      	(add_inherited_template_parms): Likewise.
      	(instantiate_class_template_1): Don't adjust
      	processing_template_decl around the call to make_friend_class.
      	adjust_processing_template_decl to adjust_template_depth.  Set
      	current_template_parms instead of processing_template_decl when
      	adjust_template_depth.
      	(make_auto_1): Inspect current_template_depth instead of the
      	magnitude of processing_template_decl.
      	(splice_late_return_type): Likewise.
      	* semantics.c (fixup_template_type): Likewise.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/concepts/diagnostic18.C: Expect a "constraints on a
      	non-templated function" error.
      	* g++.dg/cpp23/auto-fncast11.C: New test.
      561414cd
    • Patrick Palka's avatar
      c++: don't leak 'arglist' in build_new_op · 336dc544
      Patrick Palka authored
      gcc/cp/ChangeLog:
      
      	* call.c (build_new_op): Use releasing_vec for arglist.  Declare
      	conv in the scope it's used.
      336dc544
    • Patrick Palka's avatar
      c++: remove COMPOUND_EXPR_OVERLOADED flag · c5ef950d
      Patrick Palka authored
      This flag is never set because non-dependent COMPOUND_EXPRs that resolve
      to an overload are expressed as a CALL_EXPR at template definition time
      (in build_x_compound_expr) ever since r6-5772.
      
      gcc/cp/ChangeLog:
      
      	* cp-tree.h (COMPOUND_EXPR_OVERLOADED): Remove.
      	* pt.c (build_non_dependent_expr): Don't inspect the flag.
      	* tree.c (build_min_non_dep): Don't set the flag.
      c5ef950d
  10. Dec 13, 2021
  11. Dec 12, 2021
    • Jonathan Wakely's avatar
      Replace gnu::unique_ptr with std::unique_ptr · b8f7ff76
      Jonathan Wakely authored
      Now that GCC is compiled as C++11 there is no need to keep the C++03
      implementation of gnu::unique_ptr.
      
      This removes the unique-ptr.h header and replaces it with <memory> in
      system.h, and changes the INCLUDE_UNIQUE_PTR macro to INCLUDE_MEMORY.
      Uses of gnu::unique_ptr and gnu::move can be replaced with
      std::unique_ptr and std::move. There are no uses of unique_xmalloc_ptr
      or xmalloc_deleter in GCC.
      
      gcc/analyzer/ChangeLog:
      
      	* engine.cc: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
      
      gcc/c-family/ChangeLog:
      
      	* known-headers.cc: Define INCLUDE_MEMORY instead of
      	INCLUDE_UNIQUE_PTR.
      	* name-hint.h: Likewise.
      	(class name_hint): Use std::unique_ptr instead of gnu::unique_ptr.
      
      gcc/c/ChangeLog:
      
      	* c-decl.c: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
      	* c-parser.c: Likewise.
      
      gcc/cp/ChangeLog:
      
      	* error.c: Define INCLUDE_MEMORY instead of
      	INCLUDE_UNIQUE_PTR.
      	* lex.c: Likewise.
      	* name-lookup.c: Likewise.
      	(class namespace_limit_reached): Use std::unique_ptr instead of
      	gnu::unique_ptr.
      	(suggest_alternatives_for): Use std::move instead of gnu::move.
      	(suggest_alternatives_in_other_namespaces): Likewise.
      	* parser.c: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
      
      gcc/ChangeLog:
      
      	* Makefile.in: Remove unique-ptr-tests.o.
      	* selftest-run-tests.c (selftest::run_tests): Remove
      	unique_ptr_tests_cc_tests.
      	* selftest.h (unique_ptr_tests_cc_tests): Remove.
      	* system.h: Check INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR
      	and include <memory> instead of "unique-ptr.h".
      	* unique-ptr-tests.cc: Removed.
      
      include/ChangeLog:
      
      	* unique-ptr.h: Removed.
      b8f7ff76
  12. Dec 10, 2021
  13. Dec 09, 2021
    • Marek Polacek's avatar
      c++: Handle auto(x) in parameter-declaration-clause [PR103401] · 6a071b2d
      Marek Polacek authored
      In C++23, auto(x) is valid, so decltype(auto(x)) should also be valid,
      so
      
        void f(decltype(auto(0)));
      
      should be just as
      
        void f(int);
      
      but currently, everytime we see 'auto' in a parameter-declaration-clause,
      we try to synthesize_implicit_template_parm for it, creating a new template
      parameter list.  The code above actually has us calling s_i_t_p twice;
      once from cp_parser_decltype_expr -> cp_parser_postfix_expression which
      fails and then again from cp_parser_decltype_expr -> cp_parser_expression.
      So it looks like we have f<auto, auto> and we accept ill-formed code.
      
      This shows that we need to be more careful about synthesizing the
      implicit template parameter.  [dcl.spec.auto.general] says that "A
      placeholder-type-specifier of the form type-constraintopt auto can be
      used as a decl-specifier of the decl-specifier-seq of a
      parameter-declaration of a function declaration or lambda-expression..."
      so this patch turns off auto_is_... after we've parsed the decl-specifier-seq.
      
      That doesn't quite cut it yet though, because we also need to handle an
      auto nested in the decl-specifier:
      
        void f(decltype(new auto{0}));
      
      therefore the cp_parser_decltype change.
      
      To accept "sizeof(auto{10})", the cp_parser_type_id_1 hunk only gives a
      hard error when we're not parsing tentatively.
      
      The cp_parser_parameter_declaration hunk broke lambda-generic-85713-2.C but
      I think the error we issue with this patch is in fact correct, and clang++
      agrees.
      
      The r11-1913 change is OK: we need to make sure that we see '(auto)' after
      decltype to go ahead with 'decltype(auto)'.
      
      	PR c++/103401
      
      gcc/cp/ChangeLog:
      
      	* parser.c (cp_parser_decltype): Clear
      	auto_is_implicit_function_template_parm_p.
      	(cp_parser_type_id_1): Give errors only when !cp_parser_simulate_error.
      	(cp_parser_parameter_declaration): Clear
      	auto_is_implicit_function_template_parm_p after parsing the
      	decl-specifier-seq.
      	(cp_parser_sizeof_operand): Clear
      	auto_is_implicit_function_template_parm_p.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp1y/lambda-generic-85713-2.C: Add dg-error.
      	* g++.dg/cpp1y/pr60054.C: Adjust dg-error.
      	* g++.dg/cpp1y/pr60332.C: Likewise.
      	* g++.dg/cpp2a/concepts-pr84979-2.C: Likewise.
      	* g++.dg/cpp2a/concepts-pr84979-3.C: Likewise.
      	* g++.dg/cpp2a/concepts-pr84979.C: Likewise.
      	* g++.dg/cpp23/auto-fncast7.C: New test.
      	* g++.dg/cpp23/auto-fncast8.C: New test.
      	* g++.dg/cpp23/auto-fncast9.C: New test.
      6a071b2d
    • Jakub Jelinek's avatar
      pch: Add support for relocation of the PCH data [PR71934] · 747380f4
      Jakub Jelinek authored
      The following patch adds support for relocation of the PCH blob on PCH
      restore if we don't manage to get the preferred map slot for it.
      The GTY stuff knows where all the pointers are, after all it relocates
      it once during PCH save from the addresses where it was initially allocated
      to addresses in the preferred map slot.
      But, if we were to do it solely using GTY info upon PCH restore, we'd need
      another set of GTY functions, which I think would make it less maintainable
      and I think it would also be more costly at PCH restore time.  Those
      functions would need to call something to add bias to pointers that haven't
      been marked yet and make sure not to add bias to any pointer twice.
      
      So, this patch instead builds a relocation table (sorted list of addresses
      in the blob which needs relocation) at PCH save time, stores it in a very
      compact form into the gch file and upon restore, adjusts pointers in GTY
      roots (that is right away in the root structures) and the addresses in the
      relocation table.
      The cost on stdc++.gch/O2g.gch (previously 85MB large) is about 3% file size
      growth, there are 2.5 million pointers that need relocation in the gch blob
      and the relocation table uses uleb128 for address deltas and needs ~1.01 bytes
      for one address that needs relocation, and about 20% compile time during
      PCH save (I think it is mainly because of the need to qsort those 2.5
      million pointers).  On PCH restore, if it doesn't need relocation (the usual
      case), it is just an extra fread of sizeof (size_t) data and fseek
      (in my tests real time on vanilla tree for #include <bits/stdc++.h> CU
      was ~0.175s and with the patch but no relocation ~0.173s), while if it needs
      relocation it took ~0.193s, i.e. 11.5% slower.
      Without PCH that
       #include <bits/stdc++.h>
       int i;
      testcase compiles with -O2 -g in ~1.199s, i.e. 6.2 times slower than PCH with
      relocation and 6.9 times than PCH without relocation.
      
      The discovery of the pointers in the blob that need relocation is done
      in the relocate_ptrs hook which does the pointer relocation during PCH save.
      Unfortunately, I had to make one change to the gengtype stuff due to the
      nested_ptr feature of GTY, which some libcpp headers and stringpool.c use.
      The relocate_ptrs hook had 2 arguments, pointer to the pointer and a cookie.
      When relocate_ptrs is done, in most cases it is called solely on the
      subfields of the current object, so e.g.
                if ((void *)(x) == this_obj)
                  op (&((*x).u.fld[0].rt_rtx), cookie);
      so relocate_ptrs can assert that ptr_p is within the
      state->ptrs[state->ptrs_i]->obj ..
      state->ptrs[state->ptrs_i]->obj+state->ptrs[state->ptrs_i]->size-sizeof(void*)
      range and compute from that the address in the blob which will need
      relocation (state->ptrs[state->ptrs_i]->new_addr is the new address
      given to it and ptr_p-state->ptrs[state->ptrs_i]->obj is the relative
      offset.  Unfortunately, for nested_ptr gengtype emits something like:
            {
              union tree_node * x0 =
                ((*x).val.node.node) ? HT_IDENT_TO_GCC_IDENT (HT_NODE (((*x).val.node.node))) : NULL;
              if ((void *)(x) == this_obj)
                op (&(x0), cookie);
              (*x).val.node.node = (x0) ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT ((x0))) : NULL;
            }
      so relocate_ptrs is called with an address of some temporary variable and
      so doesn't know where the pointer will finally be.
      So, I've added another argument to relocate_ptrs (and to
      gt_pointer_operator).  For the most common case I pass NULL as the new middle
      argument to that function, first one remains pointer to the pointer that
      needs adjustment and last the cookie.  The NULL seems to be cheap to compute
      and short in the gt*.[ch] files and stands for ptr_p is an address within
      the this_obj's range, remember its address.  For the nested_ptr case, the
      new middle argument contains actual address of the pointer that might need
      to be relocated, so instead of the above
                op (&(x0), &((*x).val.node.node), cookie);
      in there.  And finally, e.g. for the reorder case I need a way to tell
      restore_ptrs to ignore a particular address for the relocation purposes
      and only treat it the old way.  I've used for that the case when
      the first and second arguments are equal.
      
      In order to enable support for mapping PCH as fallback at different
      addresses than the preferred ones, a small change is needed to the
      host pch_use_address hooks.  One change I've done to all of them is
      the change of the type of the first argument from void * to void *&,
      such that the actual address can be told to the callers (or shall I
      instead use void **?), but another change that still needs to be done
      in them if they want the relocation is actually not fail if they couldn't
      get a preferred address, but instead modify what the first argument
      refers to.  I've done that only for host-linux.c and Iain is testing
      similar change for host-darwin.c.  Didn't change hpux, netbsd, openbsd,
      solaris, mingw32 or the fallbacks because I can't test those.
      
      Tested also with the:
      --- gcc/config/host-linux.c.jj  2021-12-06 22:22:42.007777367 +0100
      +++ gcc/config/host-linux.c     2021-12-07 00:21:53.052674040 +0100
      @@ -191,6 +191,8 @@ linux_gt_pch_use_address (void *&base, s
         if (size == 0)
           return -1;
      
      +base = (char *) base + ((size + 8191) & (size_t) -4096);
      +
         /* Try to map the file with MAP_PRIVATE.  */
         addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, offset);
      
      hack which forces all PCH restores to be relocated.  An earlier version of the
      patch has been also regrest with base = (char *) base + 16384; in that spot,
      so both relocation to a non-overlapping spot and to an overlapping spot have
      been tested.
      
      2021-12-09  Jakub Jelinek  <jakub@redhat.com>
      
      	PR pch/71934
      	* coretypes.h (gt_pointer_operator): Use 3 pointer arguments instead
      	of two.
      	* gengtype.c (struct walk_type_data): Add in_nested_ptr argument.
      	(walk_type): Temporarily set d->in_nested_ptr around nested_ptr
      	handling.
      	(write_types_local_user_process_field): Pass a new middle pointer
      	to gt_pointer_operator op calls, if d->in_nested_ptr pass there
      	address of d->prev_val[2], otherwise NULL.
      	(write_types_local_process_field): Likewise.
      	* ggc-common.c (relocate_ptrs): Add real_ptr_p argument.  If equal
      	to ptr_p, do nothing, otherwise if NULL remember ptr_p's
      	or if non-NULL real_ptr_p's corresponding new address in
      	reloc_addrs_vec.
      	(reloc_addrs_vec): New variable.
      	(compare_ptr, read_uleb128, write_uleb128): New functions.
      	(gt_pch_save): When iterating over objects through relocate_ptrs,
      	save current i into state.ptrs_i.  Sort reloc_addrs_vec and emit
      	it as uleb128 of differences between pointer addresses into the
      	PCH file.
      	(gt_pch_restore): Allow restoring of PCH to a different address
      	than the preferred one, in that case adjust global pointers by bias
      	and also adjust by bias addresses read from the relocation table
      	as uleb128 differences.  Otherwise fseek over it.  Perform
      	gt_pch_restore_stringpool only after adjusting callbacks and for
      	callback adjustments also take into account the bias.
      	(default_gt_pch_use_address): Change type of first argument from
      	void * to void *&.
      	(mmap_gt_pch_use_address): Likewise.
      	* ggc-tests.c (gt_pch_nx): Pass NULL as new middle argument to op.
      	* hash-map.h (hash_map::pch_nx_helper): Likewise.
      	(gt_pch_nx): Likewise.
      	* hash-set.h (gt_pch_nx): Likewise.
      	* hash-table.h (gt_pch_nx): Likewise.
      	* hash-traits.h (ggc_remove::pch_nx): Likewise.
      	* hosthooks-def.h (default_gt_pch_use_address): Change type of first
      	argument from void * to void *&.
      	(mmap_gt_pch_use_address): Likewise.
      	* hosthooks.h (struct host_hooks): Change type of first argument of
      	gt_pch_use_address hook from void * to void *&.
      	* machmode.h (gt_pch_nx): Expect a callback with 3 pointers instead of
      	two in the middle argument.
      	* poly-int.h (gt_pch_nx): Likewise.
      	* stringpool.c (gt_pch_nx): Pass NULL as new middle argument to op.
      	* tree-cfg.c (gt_pch_nx): Likewise, except for LOCATION_BLOCK pass
      	the same &(block) twice.
      	* value-range.h (gt_pch_nx): Pass NULL as new middle argument to op.
      	* vec.h (gt_pch_nx): Likewise.
      	* wide-int.h (gt_pch_nx): Likewise.
      	* config/host-darwin.c (darwin_gt_pch_use_address): Change type of
      	first argument from void * to void *&.
      	* config/host-darwin.h (darwin_gt_pch_use_address): Likewise.
      	* config/host-hpux.c (hpux_gt_pch_use_address): Likewise.
      	* config/host-linux.c (linux_gt_pch_use_address): Likewise.  If
      	it couldn't succeed to mmap at the preferred location, set base
      	to the actual one.  Update addr in the manual reading loop instead of
      	base.
      	* config/host-netbsd.c (netbsd_gt_pch_use_address): Change type of
      	first argument from void * to void *&.
      	* config/host-openbsd.c (openbsd_gt_pch_use_address): Likewise.
      	* config/host-solaris.c (sol_gt_pch_use_address): Likewise.
      	* config/i386/host-mingw32.c (mingw32_gt_pch_use_address): Likewise.
      	* config/rs6000/rs6000-gen-builtins.c (write_init_file): Pass NULL
      	as new middle argument to op in the generated code.
      	* doc/gty.texi: Adjust samples for the addition of middle pointer
      	to gt_pointer_operator callback.
      gcc/ada/
      	* gcc-interface/decl.c (gt_pch_nx): Pass NULL as new middle argument
      	to op.
      gcc/c-family/
      	* c-pch.c (c_common_no_more_pch): Pass a temporary void * var
      	with NULL value instead of NULL to host_hooks.gt_pch_use_address.
      gcc/c/
      	* c-decl.c (resort_field_decl_cmp): Pass the same pointer twice
      	to resort_data.new_value.
      gcc/cp/
      	* module.cc (nop): Add another void * argument.
      	* name-lookup.c (resort_member_name_cmp): Pass the same pointer twice
      	to resort_data.new_value.
      747380f4
    • GCC Administrator's avatar
      Daily bump. · 641ff219
      GCC Administrator authored
      641ff219
  14. Dec 08, 2021
    • Chung-Lin Tang's avatar
      OpenMP 5.0: Remove array section base-pointer mapping semantics and other front-end adjustments · 6c039937
      Chung-Lin Tang authored
      This patch implements three pieces of functionality:
      
      (1) Adjust array section mapping to have standards conforming behavior,
      mapping array sections should *NOT* also map the base-pointer:
      
      struct S { int *ptr; ... };
      struct S s;
      
      Instead of generating this during gimplify:
                                    map(to:*_1 [len: 400]) map(attach:s.ptr [bias: 0])
      
      Now, adjust to:
      
      (i.e. do not map the base-pointer together. The attach operation is still
      generated, and if s.ptr is already mapped prior, attachment will happen)
      
      The correct way of achieving the base-pointer-also-mapped behavior would be to
      use:
      
      (A small Fortran front-end patch to trans-openmp.c:gfc_trans_omp_array_section
       is also included, which removes generation of a GOMP_MAP_ALWAYS_POINTER for
       array types, which appears incorrect and causes a regression in
       libgomp.fortranlibgomp.fortran/struct-elem-map-1.f90)
      
      (2) Related to the first item above, are fixes in libgomp/target.c to not
      overwrite attached pointers when handling device<->host copies, mainly for the
      "always" case.
      
      (3) The third is a set of changes to the C/C++ front-ends to extend the allowed
      component access syntax in map clauses. These changes are enabled for both
      OpenACC and OpenMP.
      
      gcc/c/ChangeLog:
      
      	* c-parser.c (struct omp_dim): New struct type for use inside
      	c_parser_omp_variable_list.
      	(c_parser_omp_variable_list): Allow multiple levels of array and
      	component accesses in array section base-pointer expression.
      	(c_parser_omp_clause_to): Set 'allow_deref' to true in call to
      	c_parser_omp_var_list_parens.
      	(c_parser_omp_clause_from): Likewise.
      	* c-typeck.c (handle_omp_array_sections_1): Extend allowed range
      	of base-pointer expressions involving INDIRECT/MEM/ARRAY_REF and
      	POINTER_PLUS_EXPR.
      	(c_finish_omp_clauses): Extend allowed ranged of expressions
      	involving INDIRECT/MEM/ARRAY_REF and POINTER_PLUS_EXPR.
      
      gcc/cp/ChangeLog:
      
      	* parser.c (struct omp_dim): New struct type for use inside
      	cp_parser_omp_var_list_no_open.
      	(cp_parser_omp_var_list_no_open): Allow multiple levels of array and
      	component accesses in array section base-pointer expression.
      	(cp_parser_omp_all_clauses): Set 'allow_deref' to true in call to
      	cp_parser_omp_var_list for to/from clauses.
      	* semantics.c (handle_omp_array_sections_1): Extend allowed range
      	of base-pointer expressions involving INDIRECT/MEM/ARRAY_REF and
      	POINTER_PLUS_EXPR.
      	(handle_omp_array_sections): Adjust pointer map generation of
      	references.
      	(finish_omp_clauses): Extend allowed ranged of expressions
      	involving INDIRECT/MEM/ARRAY_REF and POINTER_PLUS_EXPR.
      
      gcc/fortran/ChangeLog:
      
      	* trans-openmp.c (gfc_trans_omp_array_section): Do not generate
      	GOMP_MAP_ALWAYS_POINTER map for main array maps of ARRAY_TYPE type.
      
      gcc/ChangeLog:
      
      	* gimplify.c (extract_base_bit_offset): Add 'tree *offsetp' parameter,
      	accomodate case where 'offset' return of get_inner_reference is
      	non-NULL.
      	(is_or_contains_p): Further robustify conditions.
      	(omp_target_reorder_clauses): In alloc/to/from sorting phase, also
      	move following GOMP_MAP_ALWAYS_POINTER maps along.  Add new sorting
      	phase where we make sure pointers with an attach/detach map are ordered
      	correctly.
      	(gimplify_scan_omp_clauses): Add modifications to avoid creating
      	GOMP_MAP_STRUCT and associated alloc map for attach/detach maps.
      
      gcc/testsuite/ChangeLog:
      
      	* c-c++-common/goacc/deep-copy-arrayofstruct.c: Adjust testcase.
      	* c-c++-common/gomp/target-enter-data-1.c: New testcase.
      	* c-c++-common/gomp/target-implicit-map-2.c: New testcase.
      
      libgomp/ChangeLog:
      
      	* target.c (gomp_map_vars_existing): Make sure attached pointer is
      	not overwritten during cross-host/device copying.
      	(gomp_update): Likewise.
      	(gomp_exit_data): Likewise.
      	* testsuite/libgomp.c++/target-11.C: Adjust testcase.
      	* testsuite/libgomp.c++/target-12.C: Likewise.
      	* testsuite/libgomp.c++/target-15.C: Likewise.
      	* testsuite/libgomp.c++/target-16.C: Likewise.
      	* testsuite/libgomp.c++/target-17.C: Likewise.
      	* testsuite/libgomp.c++/target-21.C: Likewise.
      	* testsuite/libgomp.c++/target-23.C: Likewise.
      	* testsuite/libgomp.c/target-23.c: Likewise.
      	* testsuite/libgomp.c/target-29.c: Likewise.
      	* testsuite/libgomp.c-c++-common/target-implicit-map-2.c: New testcase.
      6c039937
    • Chung-Lin Tang's avatar
      openmp: Improve OpenMP target support for C++ (PR92120) · 0ab29cf0
      Chung-Lin Tang authored
      This patch implements several C++ specific mapping capabilities introduced for
      OpenMP 5.0, including implicit mapping of this[:1] for non-static member
      functions, zero-length array section mapping of pointer-typed members,
      lambda captured variable access in target regions, and use of lambda objects
      inside target regions.
      
      Several adjustments to the C/C++ front-ends to allow more member-access syntax
      as valid is also included.
      
      	PR middle-end/92120
      
      gcc/cp/ChangeLog:
      
      	* cp-tree.h (finish_omp_target): New declaration.
      	(finish_omp_target_clauses): Likewise.
      	* parser.c (cp_parser_omp_clause_map): Adjust call to
      	cp_parser_omp_var_list_no_open to set 'allow_deref' argument to true.
      	(cp_parser_omp_target): Factor out code, adjust into calls to new
      	function finish_omp_target.
      	* pt.c (tsubst_expr): Add call to finish_omp_target_clauses for
      	OMP_TARGET case.
      	* semantics.c (handle_omp_array_sections_1): Add handling to create
      	'this->member' from 'member' FIELD_DECL. Remove case of rejecting
      	'this' when not in declare simd.
      	(handle_omp_array_sections): Likewise.
      	(finish_omp_clauses): Likewise. Adjust to allow 'this[]' in OpenMP
      	map clauses. Handle 'A->member' case in map clauses. Remove case of
      	rejecting 'this' when not in declare simd.
      	(struct omp_target_walk_data): New struct for walking over
      	target-directive tree body.
      	(finish_omp_target_clauses_r): New function for tree walk.
      	(finish_omp_target_clauses): New function.
      	(finish_omp_target): New function.
      
      gcc/c/ChangeLog:
      
      	* c-parser.c (c_parser_omp_clause_map): Set 'allow_deref' argument in
      	call to c_parser_omp_variable_list to 'true'.
      	* c-typeck.c (handle_omp_array_sections_1): Add strip of MEM_REF in
      	array base handling.
      	(c_finish_omp_clauses): Handle 'A->member' case in map clauses.
      
      gcc/ChangeLog:
      
      	* gimplify.c ("tree-hash-traits.h"): Add include.
      	(gimplify_scan_omp_clauses): Change struct_map_to_clause to type
      	hash_map<tree_operand, tree> *. Adjust struct map handling to handle
      	cases of *A and A->B expressions. Under !DECL_P case of
      	GOMP_CLAUSE_MAP handling, add STRIP_NOPS for indir_p case, add to
      	struct_deref_set for map(*ptr_to_struct) cases. Add MEM_REF case when
      	handling component_ref_p case. Add unshare_expr and gimplification
      	when created GOMP_MAP_STRUCT is not a DECL. Add code to add
      	firstprivate pointer for *pointer-to-struct case.
      	(gimplify_adjust_omp_clauses): Move GOMP_MAP_STRUCT removal code for
      	exit data directives code to earlier position.
      	* omp-low.c (lower_omp_target):
      	Handle GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION, and
      	GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION map kinds.
      	* tree-pretty-print.c (dump_omp_clause): Likewise.
      
      gcc/testsuite/ChangeLog:
      
      	* gcc.dg/gomp/target-3.c: New testcase.
      	* g++.dg/gomp/target-3.C: New testcase.
      	* g++.dg/gomp/target-lambda-1.C: New testcase.
      	* g++.dg/gomp/target-lambda-2.C: New testcase.
      	* g++.dg/gomp/target-this-1.C: New testcase.
      	* g++.dg/gomp/target-this-2.C: New testcase.
      	* g++.dg/gomp/target-this-3.C: New testcase.
      	* g++.dg/gomp/target-this-4.C: New testcase.
      	* g++.dg/gomp/target-this-5.C: New testcase.
      	* g++.dg/gomp/this-2.C: Adjust testcase.
      
      include/ChangeLog:
      
      	* gomp-constants.h (enum gomp_map_kind):
      	Add GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION, and
      	GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION map kinds.
      	(GOMP_MAP_POINTER_P):
      	Include GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION.
      
      libgomp/ChangeLog:
      
      	* libgomp.h (gomp_attach_pointer): Add bool parameter.
      	* oacc-mem.c (acc_attach_async): Update call to gomp_attach_pointer.
      	(goacc_enter_data_internal): Likewise.
      	* target.c (gomp_map_vars_existing): Update assert condition to
      	include GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION.
      	(gomp_map_pointer): Add 'bool allow_zero_length_array_sections'
      	parameter, add support for mapping a pointer with NULL target.
      	(gomp_attach_pointer): Add 'bool allow_zero_length_array_sections'
      	parameter, add support for attaching a pointer with NULL target.
      	(gomp_map_vars_internal): Update calls to gomp_map_pointer and
      	gomp_attach_pointer, add handling for
      	GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION, and
      	GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION cases.
      	* testsuite/libgomp.c++/target-23.C: New testcase.
      	* testsuite/libgomp.c++/target-lambda-1.C: New testcase.
      	* testsuite/libgomp.c++/target-lambda-2.C: New testcase.
      	* testsuite/libgomp.c++/target-this-1.C: New testcase.
      	* testsuite/libgomp.c++/target-this-2.C: New testcase.
      	* testsuite/libgomp.c++/target-this-3.C: New testcase.
      	* testsuite/libgomp.c++/target-this-4.C: New testcase.
      	* testsuite/libgomp.c++/target-this-5.C: New testcase.
      0ab29cf0
    • GCC Administrator's avatar
      Daily bump. · 1f6b0003
      GCC Administrator authored
      1f6b0003
  15. Dec 07, 2021
    • Marek Polacek's avatar
      c++: Fix for decltype and bit-fields [PR95009] · 3a2257e6
      Marek Polacek authored
      Here, decltype deduces the wrong type for certain expressions involving
      bit-fields.  Unlike in C, in C++ bit-field width is explicitly not part
      of the type, so I think decltype should never deduce to 'int:N'.  The
      problem isn't that we're not calling unlowered_expr_type--we are--it's
      that is_bitfield_expr_with_lowered_type only handles certain codes, but
      not others.  For example, += works fine but ++ does not.
      
      This also fixes decltype-bitfield2.C where we were crashing (!), but
      unfortunately it does not fix 84516 or 70733 where the problem is likely
      a missing call to unlowered_expr_type.  It occurs to me now that typeof
      likely has had the same issue, but this patch should fix that too.
      
      	PR c++/95009
      
      gcc/cp/ChangeLog:
      
      	* typeck.c (is_bitfield_expr_with_lowered_type) <case MODIFY_EXPR>:
      	Handle UNARY_PLUS_EXPR, NEGATE_EXPR, NON_LVALUE_EXPR, BIT_NOT_EXPR,
      	P*CREMENT_EXPR too.
      
      gcc/testsuite/ChangeLog:
      
      	* g++.dg/cpp0x/decltype-bitfield1.C: New test.
      	* g++.dg/cpp0x/decltype-bitfield2.C: New test.
      3a2257e6
  16. Dec 05, 2021
  17. Dec 04, 2021
    • Jakub Jelinek's avatar
      c++: Allow indeterminate unsigned char or std::byte in bit_cast - P1272R4 · c57c910c
      Jakub Jelinek authored
      P1272R4 has added to the std::byteswap new stuff to me quite unrelated
      clarification for std::bit_cast.
      The patch treats it as DR, applying to all languages.
      We no longer diagnose if padding bits are stored into unsigned char
      or std::byte result, fields or bitfields, instead arrange for that result,
      those fields or bitfields to get indeterminate value (empty
      CONSTRUCTOR with CONSTRUCTOR_NO_ZEROING or just leaving the member's
      initializer out and setting CONSTRUCTOR_NO_ZEROING on parent).
      
      We still have a bug that we don't diagnose in lots of places lvalue-to-rvalue
      conversions of indeterminate values or class objects with some indeterminate
      members.
      
      2021-12-04  Jakub Jelinek <jakub@redhat.com>
      
      	* cp-tree.h (is_byte_access_type_not_plain_char): Declare.
      	* tree.c (is_byte_access_type_not_plain_char): New function.
      	* constexpr.c (clear_uchar_or_std_byte_in_mask): New function.
      	(cxx_eval_bit_cast): Don't error about padding bits if target
      	type is unsigned char or std::byte, instead return no clearing
      	ctor.  Use clear_uchar_or_std_byte_in_mask.
      
      	* g++.dg/cpp2a/bit-cast11.C: New test.
      	* g++.dg/cpp2a/bit-cast12.C: New test.
      	* g++.dg/cpp2a/bit-cast13.C: New test.
      	* g++.dg/cpp2a/bit-cast14.C: New test.
      c57c910c
    • GCC Administrator's avatar
      Daily bump. · 03a9bd05
      GCC Administrator authored
      03a9bd05
Loading