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 r11-8590] fold-const: Fix up fold_read_from_vector [PR100887]
Date: Thu, 17 Jun 2021 05:59:23 +0000 (GMT)	[thread overview]
Message-ID: <20210617055923.C6B553839821@sourceware.org> (raw)

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

commit r11-8590-gce1dd5e70514fde8e34c86ab45a3c55e84d3c5b7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 7 09:28:31 2021 +0200

    fold-const: Fix up fold_read_from_vector [PR100887]
    
    The callers of fold_read_from_vector expect that the index they pass is
    an index of an element in the vector and the function does that most of the
    time.  But we allow CONSTRUCTORs with VECTOR_TYPE to have VECTOR_TYPE
    elements and in that case every CONSTRUCTOR element represents not just one
    index (with the exception of V1 vectors), but multiple.
    So returning zero vector if i >= CONSTRUCTOR_NELTS or returning some
    CONSTRUCTOR_ELT's value might not be what the callers expect.
    
    Fixed by punting if the first element has vector type.
    Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
    
    In theory we could instead recurse (and assert that for CONSTRUCTORs of
    vector elements we have always all elements specified like tree-cfg.c
    verifies?) after adjusting the index appropriately.
    
    2021-06-07  Jakub Jelinek  <jakub@redhat.com>
    
            PR target/100887
            * fold-const.c (fold_read_from_vector): Return NULL if trying to
            read from a CONSTRUCTOR with vector type elements.
    
    (cherry picked from commit e1521b170b44be5cd5d36a98b6b760457b68f566)

Diff:
---
 gcc/fold-const.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 2834278fd76..a92406af79c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -15479,6 +15479,9 @@ fold_read_from_vector (tree arg, poly_uint64 idx)
 	return VECTOR_CST_ELT (arg, i);
       else if (TREE_CODE (arg) == CONSTRUCTOR)
 	{
+	  if (CONSTRUCTOR_NELTS (arg)
+	      && VECTOR_TYPE_P (TREE_TYPE (CONSTRUCTOR_ELT (arg, 0)->value)))
+	    return NULL_TREE;
 	  if (i >= CONSTRUCTOR_NELTS (arg))
 	    return build_zero_cst (TREE_TYPE (TREE_TYPE (arg)));
 	  return CONSTRUCTOR_ELT (arg, i)->value;


                 reply	other threads:[~2021-06-17  5:59 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=20210617055923.C6B553839821@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).