From a477f1445b3093d01e68cd4c096c5776ad769e11 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 22 Dec 2020 00:01:34 +0100 Subject: [PATCH] gimplify: Gimplify value in gimplify_init_ctor_eval_range [PR98353] gimplify_init_ctor_eval_range wasn't gimplifying value, so if it wasn't a gimple val, verification at the end of gimplification would ICE (or with release checking some random pass later on would ICE or misbehave). 2020-12-21 Jakub Jelinek PR c++/98353 * gimplify.c (gimplify_init_ctor_eval_range): Gimplify value before storing it into cref. * g++.dg/opt/pr98353.C: New test. --- gcc/gimplify.c | 6 +++++- gcc/testsuite/g++.dg/opt/pr98353.C | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr98353.C diff --git a/gcc/gimplify.c b/gcc/gimplify.c index ea8a53e18cb..46f726a2089 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -4607,7 +4607,11 @@ gimplify_init_ctor_eval_range (tree object, tree lower, tree upper, gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value), pre_p, cleared); else - gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value)); + { + if (gimplify_expr (&value, pre_p, NULL, is_gimple_val, fb_rvalue) + != GS_ERROR) + gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value)); + } /* We exit the loop when the index var is equal to the upper bound. */ gimplify_seq_add_stmt (pre_p, diff --git a/gcc/testsuite/g++.dg/opt/pr98353.C b/gcc/testsuite/g++.dg/opt/pr98353.C new file mode 100644 index 00000000000..e3d0a4765b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr98353.C @@ -0,0 +1,17 @@ +// PR c++/98353 +// { dg-do compile { target c++11 } } + +template struct A {}; +template +struct B +{ + static const int n = 1; + template A ::n> foo (); + _Complex double c[2], d = 1.0; +}; + +void +bar () +{ + B().foo (); +} -- 2.30.2