]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimplify: Gimplify value in gimplify_init_ctor_eval_range [PR98353]
authorJakub Jelinek <jakub@redhat.com>
Mon, 21 Dec 2020 23:01:34 +0000 (00:01 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 6 Jan 2021 09:38:38 +0000 (10:38 +0100)
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  <jakub@redhat.com>

PR c++/98353
* gimplify.c (gimplify_init_ctor_eval_range): Gimplify value before
storing it into cref.

* g++.dg/opt/pr98353.C: New test.

(cherry picked from commit a477f1445b3093d01e68cd4c096c5776ad769e11)

gcc/gimplify.c
gcc/testsuite/g++.dg/opt/pr98353.C [new file with mode: 0644]

index cd62acd6bbf918c37b47af79a327a5b6fa25b286..400f781e8651374b22062ece9c4a434b6912c14d 100644 (file)
@@ -4592,7 +4592,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 (file)
index 0000000..e3d0a47
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/98353
+// { dg-do compile { target c++11 } }
+
+template <int N> struct A {};
+template <typename T>
+struct B
+{
+  static const int n = 1;
+  template <class> A <B<T>::n> foo ();
+  _Complex double c[2], d = 1.0;
+};
+
+void
+bar ()
+{
+  B<int>().foo<int> ();
+}