]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix assertion failure in bounded_ranges::cmp [PR113496]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 10 Feb 2026 04:14:22 +0000 (23:14 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 10 Feb 2026 04:14:22 +0000 (23:14 -0500)
gcc/analyzer/ChangeLog:
PR analyzer/113496
* constraint-manager.cc (cmp_types): New.
(bounded_range::cmp): Compare the types of the constants, as well
as their values.

gcc/testsuite/ChangeLog:
PR analyzer/113496
* gcc.dg/analyzer/ice-pr113496.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/constraint-manager.cc
gcc/testsuite/gcc.dg/analyzer/ice-pr113496.c [new file with mode: 0644]

index 738ac28003f21eb82e330d6d751d5ac43c553eeb..22b8d402df01f87c775e1a4f1cb0da0518ca4798 100644 (file)
@@ -512,13 +512,28 @@ bounded_range::operator== (const bounded_range &other) const
          && tree_int_cst_equal (m_upper, other.m_upper));
 }
 
+static int
+cmp_types (const_tree type1, const_tree type2)
+{
+  int t1 = TYPE_UID (type1);
+  int t2 = TYPE_UID (type2);
+  return t1 - t2;
+}
+
 int
 bounded_range::cmp (const bounded_range &br1, const bounded_range &br2)
 {
-  if (int cmp_lower = tree_int_cst_compare (br1.m_lower,
-                                           br2.m_lower))
+  if (int cmp_lower = tree_int_cst_compare (br1.m_lower, br2.m_lower))
     return cmp_lower;
-  return tree_int_cst_compare (br1.m_upper, br2.m_upper);
+  if (int cmp_upper = tree_int_cst_compare (br1.m_upper, br2.m_upper))
+    return cmp_upper;
+  if (int cmp_lower_type = cmp_types (TREE_TYPE (br1.m_lower),
+                                     TREE_TYPE (br2.m_lower)))
+    return cmp_lower_type;
+  if (int cmp_upper_type = cmp_types (TREE_TYPE (br1.m_upper),
+                                     TREE_TYPE (br2.m_upper)))
+    return cmp_upper_type;
+  return 0;
 }
 
 /* struct bounded_ranges.  */
diff --git a/gcc/testsuite/gcc.dg/analyzer/ice-pr113496.c b/gcc/testsuite/gcc.dg/analyzer/ice-pr113496.c
new file mode 100644 (file)
index 0000000..147228b
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-additional-options "-fdump-analyzer" } */
+
+enum { PIPE_SWIZZLE_X, PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W };
+enum { UTIL_FORMAT_COLORSPACE_YUV, UTIL_FORMAT_COLORSPACE_ZS } colorspace;
+int util_format_colormask_descutil_format_colormask_colormask,
+    util_format_get_component_bits_component,
+    util_format_get_component_bits_desc_0_3_0;
+void util_format_colormask_descutil_format_colormask() {
+  switch (colorspace) {
+  case UTIL_FORMAT_COLORSPACE_YUV:
+    util_format_colormask_descutil_format_colormask_colormask = 0;
+    for (;;)
+    case UTIL_FORMAT_COLORSPACE_ZS:; /* { dg-warning "infinite loop" } */
+  }
+}
+unsigned util_format_get_component_bits() {
+  switch (util_format_get_component_bits_component)
+  case PIPE_SWIZZLE_X:
+  case PIPE_SWIZZLE_W:
+    return util_format_get_component_bits_desc_0_3_0;
+}