public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++; Fix constexpr evaluation of SPACESHIP_EXPR [PR96497]
@ 2020-08-08  9:23 Jakub Jelinek
  2020-08-10 15:30 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-08-08  9:23 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

The following valid testcase is rejected, because cxx_eval_binary_expression
is called on the SPACESHIP_EXPR with lval = true, as the address of the
spaceship needs to be passed to a method call.
After recursing on the operands and calling genericize_spaceship which turns
it into a TARGET_EXPR with initialization, we call cxx_eval_constant_expression
on it which succeeds, but then we fall through into code that will
VERIFY_CONSTANT (r) which FAILs because it is an address of a variable.  Rather
than avoiding that for lval = true and SPACESHIP_EXPR, the patch just tail
calls cxx_eval_constant_expression - I believe that call should perform all
the needed verifications.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk (and
later for 10.3)?

2020-08-08  Jakub Jelinek  <jakub@redhat.com>

	PR c++/96497
	* constexpr.c (cxx_eval_binary_expression): For SPACESHIP_EXPR, tail
	call cxx_eval_constant_expression after genericize_spaceship to avoid
	undesirable further VERIFY_CONSTANT.

	* g++.dg/cpp2a/spaceship-constexpr3.C: New test.

--- gcc/cp/constexpr.c.jj	2020-08-06 11:35:12.997122440 +0200
+++ gcc/cp/constexpr.c	2020-08-07 13:30:28.732376843 +0200
@@ -3085,8 +3085,8 @@ cxx_eval_binary_expression (const conste
   else if (code == SPACESHIP_EXPR)
     {
       r = genericize_spaceship (type, lhs, rhs);
-      r = cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
-					overflow_p);
+      return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
+					   overflow_p);
     }
 
   if (r == NULL_TREE)
--- gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C.jj	2020-08-07 13:37:34.883410112 +0200
+++ gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C	2020-08-07 13:38:09.988918586 +0200
@@ -0,0 +1,7 @@
+// PR c++/96497
+// { dg-do compile { target c++20 } }
+
+#include <compare>
+
+static_assert(std::partial_ordering(std::strong_ordering::less) < 0);
+static_assert(std::partial_ordering(1 <=> 2) < 0);

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++; Fix constexpr evaluation of SPACESHIP_EXPR [PR96497]
  2020-08-08  9:23 [PATCH] c++; Fix constexpr evaluation of SPACESHIP_EXPR [PR96497] Jakub Jelinek
@ 2020-08-10 15:30 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-08-10 15:30 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 8/8/20 5:23 AM, Jakub Jelinek wrote:
> Hi!
> 
> The following valid testcase is rejected, because cxx_eval_binary_expression
> is called on the SPACESHIP_EXPR with lval = true, as the address of the
> spaceship needs to be passed to a method call.
> After recursing on the operands and calling genericize_spaceship which turns
> it into a TARGET_EXPR with initialization, we call cxx_eval_constant_expression
> on it which succeeds, but then we fall through into code that will
> VERIFY_CONSTANT (r) which FAILs because it is an address of a variable.  Rather
> than avoiding that for lval = true and SPACESHIP_EXPR, the patch just tail
> calls cxx_eval_constant_expression - I believe that call should perform all
> the needed verifications.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk (and
> later for 10.3)?

OK.

> 2020-08-08  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/96497
> 	* constexpr.c (cxx_eval_binary_expression): For SPACESHIP_EXPR, tail
> 	call cxx_eval_constant_expression after genericize_spaceship to avoid
> 	undesirable further VERIFY_CONSTANT.
> 
> 	* g++.dg/cpp2a/spaceship-constexpr3.C: New test.
> 
> --- gcc/cp/constexpr.c.jj	2020-08-06 11:35:12.997122440 +0200
> +++ gcc/cp/constexpr.c	2020-08-07 13:30:28.732376843 +0200
> @@ -3085,8 +3085,8 @@ cxx_eval_binary_expression (const conste
>     else if (code == SPACESHIP_EXPR)
>       {
>         r = genericize_spaceship (type, lhs, rhs);
> -      r = cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
> -					overflow_p);
> +      return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
> +					   overflow_p);
>       }
>   
>     if (r == NULL_TREE)
> --- gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C.jj	2020-08-07 13:37:34.883410112 +0200
> +++ gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C	2020-08-07 13:38:09.988918586 +0200
> @@ -0,0 +1,7 @@
> +// PR c++/96497
> +// { dg-do compile { target c++20 } }
> +
> +#include <compare>
> +
> +static_assert(std::partial_ordering(std::strong_ordering::less) < 0);
> +static_assert(std::partial_ordering(1 <=> 2) < 0);
> 
> 	Jakub
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-10 15:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-08  9:23 [PATCH] c++; Fix constexpr evaluation of SPACESHIP_EXPR [PR96497] Jakub Jelinek
2020-08-10 15:30 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).