]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix ICE on (X + (-X)) for vectors [PR124188]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 24 Feb 2026 22:16:59 +0000 (17:16 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 24 Feb 2026 22:16:59 +0000 (17:16 -0500)
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>
gcc/analyzer/region-model-manager.cc
gcc/testsuite/c-c++-common/analyzer/vector-ice-pr124188.c [new file with mode: 0644]

index c7aaa38a0949c66bad58c31a33756f4155e15a93..892d60697be2f0263beafe326d12202904f50cae 100644 (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 ())
diff --git a/gcc/testsuite/c-c++-common/analyzer/vector-ice-pr124188.c b/gcc/testsuite/c-c++-common/analyzer/vector-ice-pr124188.c
new file mode 100644 (file)
index 0000000..8fff31d
--- /dev/null
@@ -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;
+}