]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ensure arguments to range-op handler are supported.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 6 Dec 2022 15:41:29 +0000 (10:41 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 8 Dec 2022 13:52:55 +0000 (08:52 -0500)
PR tree-optimization/107985
gcc/
* gimple-range-op.cc
(gimple_range_op_handler::gimple_range_op_handler): Check if type
of the operands is supported.
* gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Do
not assert if here is no range-op handler.

gcc/testsuite/
* g++.dg/pr107985.C: New.

gcc/gimple-range-op.cc
gcc/gimple-range.cc
gcc/testsuite/g++.dg/pr107985.C [new file with mode: 0644]

index 7764166d5fb1a6bfef1a97e288803d05f09f2611..12068544bc5cffa9082b8b18f11c554b21220cac 100644 (file)
@@ -148,6 +148,9 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s)
        case GIMPLE_COND:
          m_op1 = gimple_cond_lhs (m_stmt);
          m_op2 = gimple_cond_rhs (m_stmt);
+         // Check that operands are supported types.  One check is enough.
+         if (!Value_Range::supports_type_p (TREE_TYPE (m_op1)))
+           m_valid = false;
          return;
        case GIMPLE_ASSIGN:
          m_op1 = gimple_range_base_of_assignment (m_stmt);
@@ -164,6 +167,9 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s)
            }
          if (gimple_num_ops (m_stmt) >= 3)
            m_op2 = gimple_assign_rhs2 (m_stmt);
+         // Check that operands are supported types.  One check is enough.
+         if ((m_op1 && !Value_Range::supports_type_p (TREE_TYPE (m_op1))))
+           m_valid = false;
          return;
        default:
          gcc_unreachable ();
index ecd6039e0fd5149539be4b2b37fa2d69270c510b..8c055826e176a6f6216c68365dd73d37df211f39 100644 (file)
@@ -422,18 +422,20 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa)
       else
        {
          gimple_range_op_handler handler (stmt);
-         gcc_checking_assert (handler);
-         tree op = handler.operand2 ();
-         if (op)
+         if (handler)
            {
-             Value_Range r (TREE_TYPE (op));
-             prefill_name (r, op);
-           }
-         op = handler.operand1 ();
-         if (op)
-           {
-             Value_Range r (TREE_TYPE (op));
-             prefill_name (r, op);
+             tree op = handler.operand2 ();
+             if (op)
+               {
+                 Value_Range r (TREE_TYPE (op));
+                 prefill_name (r, op);
+               }
+             op = handler.operand1 ();
+             if (op)
+               {
+                 Value_Range r (TREE_TYPE (op));
+                 prefill_name (r, op);
+               }
            }
        }
     }
diff --git a/gcc/testsuite/g++.dg/pr107985.C b/gcc/testsuite/g++.dg/pr107985.C
new file mode 100644 (file)
index 0000000..8d244b5
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -ftree-vrp -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre" } */
+
+struct B {
+  int f;
+};
+
+struct D : public B {
+};
+
+void foo() {
+  D d;
+  d.f = 7;
+
+  int B::* pfb = &B::f;
+  int D::* pfd = pfb;
+  int v = d.*pfd;
+}