This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix ICE with SIZEOF_EXPR in default arg (PR c++/71822)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 18 Jul 2016 14:24:30 -0400
- Subject: Re: [C++ PATCH] Fix ICE with SIZEOF_EXPR in default arg (PR c++/71822)
- Authentication-results: sourceware.org; auth=none
- References: <20160711192557.GN7387@tucnak.redhat.com>
OK.
On Mon, Jul 11, 2016 at 3:25 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> For SIZEOF_EXPR, we rely on cp_fold to fold it.
> But, for VEC_INIT_EXPR initialization, we actually just genericize it
> without ever folding the expressions, so e.g. if the ctor has default args
> and some complicated expressions in there, they will never be cp_folded.
> This is the only place that calls cp_genericize_tree other than when the
> whole function is genericized, the fix just adds similar folding of the
> expression that cp_fold_function does.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2?
>
> 2016-07-11 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/71822
> * cp-gimplify.c (cp_gimplify_expr) <case VEC_INIT_EXPR>: Recursively
> fold *expr_p before genericizing it.
>
> * g++.dg/template/defarg21.C: New test.
>
> --- gcc/cp/cp-gimplify.c.jj 2016-07-11 11:14:28.000000000 +0200
> +++ gcc/cp/cp-gimplify.c 2016-07-11 11:24:30.554083084 +0200
> @@ -621,6 +621,8 @@ cp_gimplify_expr (tree *expr_p, gimple_s
> init, VEC_INIT_EXPR_VALUE_INIT (*expr_p),
> from_array,
> tf_warning_or_error);
> + hash_set<tree> pset;
> + cp_walk_tree (expr_p, cp_fold_r, &pset, NULL);
> cp_genericize_tree (expr_p);
> ret = GS_OK;
> input_location = loc;
> --- gcc/testsuite/g++.dg/template/defarg21.C.jj 2016-07-11 11:32:34.262266398 +0200
> +++ gcc/testsuite/g++.dg/template/defarg21.C 2016-07-11 11:31:21.000000000 +0200
> @@ -0,0 +1,21 @@
> +// PR c++/71822
> +// { dg-do compile }
> +
> +int bar (int);
> +
> +template <typename T>
> +struct A
> +{
> + explicit A (int x = bar (sizeof (T)));
> +};
> +
> +struct B
> +{
> + A <int> b[2];
> +};
> +
> +void
> +baz ()
> +{
> + B b;
> +}
>
> Jakub