[PATCH] c++: Fix ICE with non-constant satisfaction [PR98644]

Jason Merrill jason@redhat.com
Tue Jan 19 20:40:51 GMT 2021


On 1/13/21 12:05 PM, Patrick Palka wrote:
> In the below testcase, the expression of the atomic constraint after
> substitution is (int *) NON_LVALUE_EXPR <1> != 0B which is not a C++
> constant expression, but its TREE_CONSTANT flag is set (from build2),
> so satisfy_atom fails to notice that it's non-constant (and we end
> up tripping over the assert in satisfaction_value).
> 
> Since TREE_CONSTANT doesn't necessarily correspond to C++ constantness,
> this patch makes satisfy_atom instead check is_rvalue_constant_expression.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/10?
> 
> gcc/cp/ChangeLog:
> 
> 	PR c++/98644
> 	* constraint.cc (satisfy_atom): Check is_rvalue_constant_expression
> 	instead of TREE_CONSTANT.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/98644
> 	* g++.dg/cpp2a/concepts-pr98644.C: New test.
> ---
>   gcc/cp/constraint.cc                          | 2 +-
>   gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C | 7 +++++++
>   2 files changed, 8 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C
> 
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 9049d087859..f99a25dc8a4 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -2969,7 +2969,7 @@ satisfy_atom (tree t, tree args, sat_info info)
>       {
>         result = maybe_constant_value (result, NULL_TREE,
>   				     /*manifestly_const_eval=*/true);
> -      if (!TREE_CONSTANT (result))

This should be sufficient.  If the result isn't constant, 
maybe_constant_value shouldn't return it with TREE_CONSTANT set.  See

>       /* This isn't actually constant, so unset TREE_CONSTANT.                                                 

in cxx_eval_outermost_constant_expr.

Jason



More information about the Gcc-patches mailing list