This was leading to an assertion failure ICE on a switch stmt when using
-fstrict-enums, due to erroneously reusing a range involving one enum
with a range involving a different enum.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r12-5307-ge1c0c908f85816240b685a5be4f0e5a0e6634979.

gcc/analyzer/ChangeLog:
        PR analyzer/102662
        * constraint-manager.cc (bounded_range::operator==): Require the
        types to be the same for equality.

gcc/testsuite/ChangeLog:
        PR analyzer/102662
        * g++.dg/analyzer/pr102662.C: New test.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/analyzer/constraint-manager.cc       |  4 ++-
 gcc/testsuite/g++.dg/analyzer/pr102662.C | 39 ++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/analyzer/pr102662.C

diff --git a/gcc/analyzer/constraint-manager.cc 
b/gcc/analyzer/constraint-manager.cc
index 6df23fb477e..ea6b5dc60e0 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -432,7 +432,9 @@ bounded_range::intersects_p (const bounded_range &other,
 bool
 bounded_range::operator== (const bounded_range &other) const
 {
-  return (tree_int_cst_equal (m_lower, other.m_lower)
+  return (TREE_TYPE (m_lower) == TREE_TYPE (other.m_lower)
+         && TREE_TYPE (m_upper) == TREE_TYPE (other.m_upper)
+         && tree_int_cst_equal (m_lower, other.m_lower)
          && tree_int_cst_equal (m_upper, other.m_upper));
 }
 
diff --git a/gcc/testsuite/g++.dg/analyzer/pr102662.C 
b/gcc/testsuite/g++.dg/analyzer/pr102662.C
new file mode 100644
index 00000000000..99252c7d109
--- /dev/null
+++ b/gcc/testsuite/g++.dg/analyzer/pr102662.C
@@ -0,0 +1,39 @@
+/* { dg-additional-options "-fstrict-enums" } */
+
+enum OpCode {
+  OP_MOVE,
+  OP_LOADK,
+  OP_LOADBOOL,
+  OP_LOADNIL,
+  OP_GETUPVAL,
+  OP_SETUPVAL
+};
+
+enum OpArg {
+  OpArgN,
+  OpArgU,
+  OpArgR,
+  OpArgK
+};
+
+void
+symbexec_lastpc (enum OpCode symbexec_lastpc_op, enum OpArg luaP_opmodes)
+{
+  switch (luaP_opmodes)
+    {
+    case OpArgN:
+    case OpArgK:
+      {
+        switch (symbexec_lastpc_op)
+          {
+          case OP_LOADNIL:
+          case OP_SETUPVAL:
+            break;
+          default:
+            break;
+          }
+      }
+    default:
+      break;
+    }
+}
-- 
2.26.3

Reply via email to