]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix 32-bit spaceship failures [PR110185]
authorJason Merrill <jason@redhat.com>
Fri, 9 Jun 2023 14:37:35 +0000 (10:37 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 9 Jun 2023 15:41:42 +0000 (11:41 -0400)
Various spaceship tests failed after r14-1624.  This turned out to be
because the comparison category classes return in memory on 32-bit targets,
and the synthesized operator<=> looks something like

if (auto v = a.x <=> b.x, v == 0); else return v;
if (auto v = a.y <=> b.y, v == 0); else return v;
etc.

so check_return_expr was trying to do NRVO for all the 'v' variables, and
now on subsequent returns we check to see if the previous NRV is still in
scope.  But the NRVs didn't have names, so looking up name bindings crashed.
Fixed both by giving 'v' a name so we can NRVO the first one, and fixing the
test to give up if the old NRV has no name.

PR c++/110185
PR c++/58487

gcc/cp/ChangeLog:

* method.cc (build_comparison_op): Give retval a name.
* typeck.cc (check_return_expr): Fix for nameless variables.

gcc/cp/method.cc
gcc/cp/typeck.cc

index 0c2ca9e4f4165693e9def002225ef6a1b1c77dd0..91cf943f11089c0e6bcbe8377daa4e016f956d56 100644 (file)
@@ -1679,6 +1679,7 @@ build_comparison_op (tree fndecl, bool defining, tsubst_flags_t complain)
              if (defining)
                {
                  tree var = create_temporary_var (rettype);
+                 DECL_NAME (var) = get_identifier ("retval");
                  pushdecl (var);
                  cp_finish_decl (var, comp, false, NULL_TREE, flags);
                  comp = retval = var;
index 11927cbdf83079b97f05828ea7b3809460e6926f..da591dafc8ff7e3d2d595868da7e91684793e9eb 100644 (file)
@@ -11174,6 +11174,7 @@ check_return_expr (tree retval, bool *no_warning)
        current_function_return_value = bare_retval;
       else if (current_function_return_value
               && VAR_P (current_function_return_value)
+              && DECL_NAME (current_function_return_value)
               && !decl_in_scope_p (current_function_return_value))
        {
          /* The earlier NRV is out of scope at this point, so it's safe to