[committed] analyzer: fix ICE due to comparing int and real constants (PR 93547)

Message ID 20200203193654.10135-1-dmalcolm@redhat.com
State New
Headers show
Series
  • [committed] analyzer: fix ICE due to comparing int and real constants (PR 93547)
Related show

Commit Message

David Malcolm Feb. 3, 2020, 7:36 p.m.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to master as r10-6409-g287ccd3bd6b92f11ec90c52ffccb764aacfadb89.

gcc/analyzer/ChangeLog:
	PR analyzer/93547
	* constraint-manager.cc
	(constraint_manager::get_or_add_equiv_class): Ensure types are
	compatible before comparing constants.

gcc/testsuite/ChangeLog:
	PR analyzer/93547
	* gcc.dg/analyzer/pr93547.c: New test.
---
 gcc/analyzer/constraint-manager.cc      |  4 +++-
 gcc/testsuite/gcc.dg/analyzer/pr93547.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr93547.c

-- 
2.21.0

Patch

diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc
index f3e31ee0830..4042c50fcb7 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -928,7 +928,9 @@  constraint_manager::get_or_add_equiv_class (svalue_id sid)
       int i;
       equiv_class *ec;
       FOR_EACH_VEC_ELT (m_equiv_classes, i, ec)
-	if (ec->m_constant)
+	if (ec->m_constant
+	    && types_compatible_p (TREE_TYPE (cst),
+				   TREE_TYPE (ec->m_constant)))
 	  {
 	    tree eq = fold_build2 (EQ_EXPR, boolean_type_node,
 				   cst, ec->m_constant);
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr93547.c b/gcc/testsuite/gcc.dg/analyzer/pr93547.c
new file mode 100644
index 00000000000..15189048234
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr93547.c
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+
+void
+wy (int);
+
+int
+f9 (void)
+{
+  int p5 = __builtin_ilogb (__builtin_inf ());
+
+  wy (0);
+
+  return p5;
+}