analyzer: fix ICE on (X + (-X)) for vectors [PR124188]

gcc/analyzer/ChangeLog:
	PR analyzer/124188
	* region-model-manager.cc
	(region_model_manager::maybe_fold_binop): Don't attempt to fold
	X + (-X) to zero for vector types.

gcc/testsuite/ChangeLog:
	PR analyzer/124188
	* c-c++-common/analyzer/vector-ice-pr124188.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm
2026-02-24 17:16:59 -05:00
parent 761e0d3d78
commit fdc38baeea
2 changed files with 14 additions and 1 deletions

View File

@@ -683,7 +683,8 @@ region_model_manager::maybe_fold_binop (tree type, enum tree_code op,
/* X + (-X) -> 0. */
if (const unaryop_svalue *unary_op = arg1->dyn_cast_unaryop_svalue ())
if (unary_op->get_op () == NEGATE_EXPR
&& unary_op->get_arg () == arg0)
&& unary_op->get_arg () == arg0
&& type && (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)))
return get_or_create_int_cst (type, 0);
/* X + (Y - X) -> Y. */
if (const binop_svalue *bin_op = arg1->dyn_cast_binop_svalue ())

View File

@@ -0,0 +1,12 @@
/* { dg-additional-options "-Wno-psabi" } */
typedef __attribute__((__vector_size__(64))) char V;
V g;
void
foo(V a)
{
V v = -a;
a + v + g;
}