analyzer: fix ICE comparing VECTOR_CSTs [PR105252]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 13 Apr 2022 16:02:07 +0000 (12:02 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 14 Apr 2022 12:50:17 +0000 (08:50 -0400)
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>
gcc/analyzer/svalue.cc
gcc/testsuite/gcc.dg/analyzer/pr105252.c [new file with mode: 0644]

index 553edae..536bc28 100644 (file)
@@ -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 (file)
index 0000000..a093eab
--- /dev/null
@@ -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);
+}