analyzer: fix ICE on folding vector 0 [PR96705]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 19 Aug 2020 13:27:16 +0000 (09:27 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 19 Aug 2020 19:26:10 +0000 (15:26 -0400)
gcc/analyzer/ChangeLog:
* region-model-manager.cc
PR analyzer/96705
(region_model_manager::maybe_fold_binop): Check that we have an
integral type before calling build_int_cst.

gcc/testsuite/ChangeLog:
PR analyzer/96705
* gcc.dg/analyzer/pr96705.c: New test.

gcc/analyzer/region-model-manager.cc
gcc/testsuite/gcc.dg/analyzer/pr96705.c [new file with mode: 0644]

index 07925743ab0f0e825f53b95be199e5303b074338..422c4a95e7bd73ba4633c8711e08058f8aa7bc50 100644 (file)
@@ -445,7 +445,7 @@ region_model_manager::maybe_fold_binop (tree type, enum tree_code op,
       break;
     case MULT_EXPR:
       /* (VAL * 0).  */
-      if (cst1 && zerop (cst1))
+      if (cst1 && zerop (cst1) && INTEGRAL_TYPE_P (type))
        return get_or_create_constant_svalue (build_int_cst (type, 0));
       /* (VAL * 1) -> VAL.  */
       if (cst1 && integer_onep (cst1))
@@ -455,7 +455,7 @@ region_model_manager::maybe_fold_binop (tree type, enum tree_code op,
     case TRUTH_AND_EXPR:
       if (cst1)
        {
-         if (zerop (cst1))
+         if (zerop (cst1) && INTEGRAL_TYPE_P (type))
            /* "(ARG0 && 0)" -> "0".  */
            return get_or_create_constant_svalue (build_int_cst (type, 0));
          else
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96705.c b/gcc/testsuite/gcc.dg/analyzer/pr96705.c
new file mode 100644 (file)
index 0000000..d7856d2
--- /dev/null
@@ -0,0 +1,9 @@
+int __attribute__ ((vector_size (8))) v;
+int i;
+
+void
+test (void)
+{
+  v &= 0;
+  v *= i;
+}