public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-8159] analyzer: fix ICE comparing VECTOR_CSTs [PR105252]
Date: Thu, 14 Apr 2022 12:51:39 +0000 (GMT)	[thread overview]
Message-ID: <20220414125139.D75A83858C54@sourceware.org> (raw)

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

commit r12-8159-gb209a349268d245f7a318861112df47bea15b89d
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Wed Apr 13 12:02:07 2022 -0400

    analyzer: fix ICE comparing VECTOR_CSTs [PR105252]
    
    gcc/analyzer/ChangeLog:
            PR analyzer/105252
            * svalue.cc (cmp_cst): When comparing VECTOR_CSTs, compare the
            types of the encoded elements before calling cmp_cst on them.
    
    gcc/testsuite/ChangeLog:
            PR analyzer/105252
            * gcc.dg/analyzer/pr105252.c: New test.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/svalue.cc                   | 13 ++++++++++---
 gcc/testsuite/gcc.dg/analyzer/pr105252.c | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/gcc/analyzer/svalue.cc b/gcc/analyzer/svalue.cc
index 553edae7250..536bc288dbf 100644
--- a/gcc/analyzer/svalue.cc
+++ b/gcc/analyzer/svalue.cc
@@ -337,9 +337,16 @@ cmp_cst (const_tree cst1, const_tree cst2)
 	return cmp_nelts_per_pattern;
       unsigned encoded_nelts = vector_cst_encoded_nelts (cst1);
       for (unsigned i = 0; i < encoded_nelts; i++)
-	if (int el_cmp = cmp_cst (VECTOR_CST_ENCODED_ELT (cst1, i),
-				  VECTOR_CST_ENCODED_ELT (cst2, i)))
-	  return el_cmp;
+	{
+	  const_tree elt1 = VECTOR_CST_ENCODED_ELT (cst1, i);
+	  const_tree elt2 = VECTOR_CST_ENCODED_ELT (cst2, i);
+	  int t1 = TYPE_UID (TREE_TYPE (elt1));
+	  int t2 = TYPE_UID (TREE_TYPE (elt2));
+	  if (int cmp_type = t1 - t2)
+	    return cmp_type;
+	  if (int el_cmp = cmp_cst (elt1, elt2))
+	    return el_cmp;
+	}
       return 0;
     }
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr105252.c b/gcc/testsuite/gcc.dg/analyzer/pr105252.c
new file mode 100644
index 00000000000..a093eababc5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr105252.c
@@ -0,0 +1,20 @@
+/* { dg-additional-options "-fnon-call-exceptions -O" } */
+
+typedef unsigned char C;
+typedef unsigned char __attribute__((__vector_size__ (4))) V;
+
+C m;
+
+static inline void
+bar (C c, V v, V *r)
+{
+  v %= (c | v) % m;
+  *r = v;
+}
+
+void
+foo (void)
+{
+  V x;
+  bar (0, (V){2}, &x);
+}


                 reply	other threads:[~2022-04-14 12:51 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=20220414125139.D75A83858C54@sourceware.org \
    --to=dmalcolm@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).