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 r12-6881] c++: Fix up handling of vector CONSTRUCTORs with vectors in it in constexpr.cc [PR104226]
Date: Wed, 26 Jan 2022 18:41:48 +0000 (GMT)	[thread overview]
Message-ID: <20220126184148.58926382C400@sourceware.org> (raw)

https://gcc.gnu.org/g:abea1c9a252ef7712ab800360e1e0e2697ee14f2

commit r12-6881-gabea1c9a252ef7712ab800360e1e0e2697ee14f2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jan 26 19:40:29 2022 +0100

    c++: Fix up handling of vector CONSTRUCTORs with vectors in it in constexpr.cc [PR104226]
    
    The middle-end uses sometimes VECTOR_TYPE CONSTRUCTORs that contain
    some other VECTOR_TYPE elements in it (should be with compatible element
    size and smaller number of elements, e.g. a V8SImode vector can be
    constructed as { V4SImode_var_1, V4SImode_var_2 }), and expansion of
    __builtin_shufflevector emits these early, so constexpr.cc can see those
    too.
    constexpr.cc already has special cases for NULL index which is typical
    for VECTOR_TYPE CONSTRUCTORs, and for VECTOR_TYPE CONSTRUCTORs that
    contain just scalar elts that works just fine - init_subob_ctx just
    returns on non-aggregate elts and get_or_insert_ctor_field has
      if (TREE_CODE (type) == VECTOR_TYPE && index == NULL_TREE)
        {
          CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (ctor), index, NULL_TREE);
          return &CONSTRUCTOR_ELTS (ctor)->last();
        }
    handling for it.  But for the vector in vector case init_subob_ctx would
    try to create a sub-CONSTRUCTOR and even didn't handle the NULL index
    case well, so instead of creating the sub-CONSTRUCTOR after the elts already
    in it overwrote the first one.  So
    (V8SImode) { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }
    became
    (V8SImode) { 0, 0, 0, 0 }
    The following patch fixes it by not forcing a sub-CONSTRUCTOR for this
    vector in vector case.
    
    2022-01-26  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/104226
            * constexpr.cc (init_subob_ctx): For vector ctors containing
            vector elements, ensure appending to the same ctor instead of
            creating another one.
    
            * g++.dg/cpp0x/constexpr-104226.C: New test.

Diff:
---
 gcc/cp/constexpr.cc                           |  7 +++++++
 gcc/testsuite/g++.dg/cpp0x/constexpr-104226.C | 15 +++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index dcc167499ed..7f4425326be 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -4658,6 +4658,13 @@ init_subob_ctx (const constexpr_ctx *ctx, constexpr_ctx &new_ctx,
   if (!AGGREGATE_TYPE_P (type) && !VECTOR_TYPE_P (type))
     /* A non-aggregate member doesn't get its own CONSTRUCTOR.  */
     return;
+  if (VECTOR_TYPE_P (type)
+      && VECTOR_TYPE_P (TREE_TYPE (ctx->ctor))
+      && index == NULL_TREE)
+    /* A vector inside of a vector CONSTRUCTOR, e.g. when a larger
+       vector is constructed from smaller vectors, doesn't get its own
+       CONSTRUCTOR either.  */
+    return;
 
   /* The sub-aggregate initializer might contain a placeholder;
      update object to refer to the subobject and ctor to refer to
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-104226.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-104226.C
new file mode 100644
index 00000000000..a44f417f7ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-104226.C
@@ -0,0 +1,15 @@
+// PR c++/104226
+// { dg-do compile }
+// { dg-options "-Wno-psabi" }
+
+typedef unsigned short __attribute__((__vector_size__(16))) U;
+typedef unsigned int __attribute__((__vector_size__(16))) V;
+typedef unsigned int __attribute__((__vector_size__(32))) W;
+
+U
+foo (void)
+{
+  return __builtin_convertvector (__builtin_shufflevector ((V){}, (W){},
+							   0, 0, 1, 0,
+							   5, 5, 0, 2), U);
+}


                 reply	other threads:[~2022-01-26 18:41 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=20220126184148.58926382C400@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).