public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r9-9403] gimplify: Gimplify value in gimplify_init_ctor_eval_range [PR98353]
Date: Tue, 20 Apr 2021 23:30:58 +0000 (GMT)	[thread overview]
Message-ID: <20210420233058.0ECD03AA7C9E@sourceware.org> (raw)

https://gcc.gnu.org/g:202240b05f28681053c64efbf1e6deb07f36e1b8

commit r9-9403-g202240b05f28681053c64efbf1e6deb07f36e1b8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Dec 22 00:01:34 2020 +0100

    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  <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 f3113a85f098df8165624321cc85d20219fb2ada)

Diff:
---
 gcc/gimplify.c                     |  6 +++++-
 gcc/testsuite/g++.dg/opt/pr98353.C | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 8c30910d90d..ae3cd1a3828 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -4497,7 +4497,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 <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> ();
+}


                 reply	other threads:[~2021-04-20 23:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210420233058.0ECD03AA7C9E@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).