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>
This commit is contained in:
David Malcolm 2022-04-13 12:02:07 -04:00
parent ba2f60499d
commit b209a34926
2 changed files with 30 additions and 3 deletions

View 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;
}
}

View File

@ -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);
}