]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix calc_op1 for undefined op2_range.
authorAndrew MacLeod <amacleod@redhat.com>
Thu, 22 Sep 2022 14:27:17 +0000 (10:27 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 22 Sep 2022 18:48:28 +0000 (14:48 -0400)
Unary operations pass the type of operand 1 into op1_range.  If that
range is undefined, the routine blindly picks the type of operand 2,
which in the case of a unary op, does not exist and traps.

* gimple-range-op.cc (gimple_range_op_handler::calc_op1): Use
  operand 1 for second range if there is no operand 2.

gcc/gimple-range-op.cc

index f03125a0fc58115124e9ccfb6bdc1f4c6ee19f62..ab5b389449d0b09128f468c513c36883df17e4d4 100644 (file)
@@ -208,10 +208,14 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range,
   // If op2 is undefined, solve as if it is varying.
   if (op2_range.undefined_p ())
     {
-      // This is sometimes invoked on single operand stmts.
       if (gimple_num_ops (m_stmt) < 3)
        return false;
-      tree op2_type = TREE_TYPE (operand2 ());
+      tree op2_type;
+      // This is sometimes invoked on single operand stmts.
+      if (operand2 ())
+       op2_type = TREE_TYPE (operand2 ());
+      else
+       op2_type = TREE_TYPE (operand1 ());
       Value_Range trange (op2_type);
       trange.set_varying (op2_type);
       return op1_range (r, type, lhs_range, trange);