public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/84424, ICE with constexpr and __builtin_shuffle.
Date: Thu, 22 Feb 2018 22:50:00 -0000	[thread overview]
Message-ID: <CADzB+2kB4Lp+O9kf1R+kJ_w1c3+ZnjD+2iT4eGkPCcdx0BfSig@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 257 bytes --]

We were crashing when checking whether the value being created for v
is constant, because TYPE_FIELDS is invalid for VECTOR_TYPE.  But it's
easy enough to just return false for a partially-initialized vector.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 84424.diff --]
[-- Type: text/plain, Size: 1523 bytes --]

commit 0a07b4d11d758ccbfe11012fcbc7ee6e94f2b3d0
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Feb 22 17:29:54 2018 -0500

            PR c++/84424 - ICE with constexpr and __builtin_shuffle.
    
            * constexpr.c (reduced_constant_expression_p): Handle CONSTRUCTOR of
            VECTOR_TYPE.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index f095b038d32..47ff90cb055 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1763,7 +1763,13 @@ reduced_constant_expression_p (tree t)
       /* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR.  */
       tree idx, val, field; unsigned HOST_WIDE_INT i;
       if (CONSTRUCTOR_NO_IMPLICIT_ZERO (t))
-	field = next_initializable_field (TYPE_FIELDS (TREE_TYPE (t)));
+	{
+	  if (TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
+	    /* An initialized vector would have a VECTOR_CST.  */
+	    return false;
+	  else
+	    field = next_initializable_field (TYPE_FIELDS (TREE_TYPE (t)));
+	}
       else
 	field = NULL_TREE;
       FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, idx, val)
diff --git a/gcc/testsuite/g++.dg/ext/vector34.C b/gcc/testsuite/g++.dg/ext/vector34.C
new file mode 100644
index 00000000000..5cca53070b2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/vector34.C
@@ -0,0 +1,8 @@
+// PR c++/84424
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+typedef int vec __attribute__ ((vector_size (2 * sizeof (int))));
+
+constexpr vec u = { 1, 2 };
+constexpr vec v = __builtin_shuffle (v, u); // { dg-error "" }

                 reply	other threads:[~2018-02-22 22:50 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=CADzB+2kB4Lp+O9kf1R+kJ_w1c3+ZnjD+2iT4eGkPCcdx0BfSig@mail.gmail.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@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).