]> gcc.gnu.org Git - gcc.git/commitdiff
analyzer: fix overeager sharing of bounded_range instances [PR102662]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 15 Nov 2021 21:12:37 +0000 (16:12 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 16 Nov 2021 15:23:04 +0000 (10:23 -0500)
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.

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 <dmalcolm@redhat.com>
gcc/analyzer/constraint-manager.cc
gcc/testsuite/g++.dg/analyzer/pr102662.C [new file with mode: 0644]

index 6df23fb477ead9e15f3b8b8fbf164eea1e64706f..ea6b5dc60e02fb10980f0bddb03c5f2d362c0079 100644 (file)
@@ -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 (file)
index 0000000..99252c7
--- /dev/null
@@ -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;
+    }
+}
This page took 0.074607 seconds and 5 git commands to generate.