OSDN Git Service

* fold-const.c (fold_binary_op_with_conditional_arg): Improve
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 Oct 2002 23:07:48 +0000 (23:07 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 Oct 2002 23:07:48 +0000 (23:07 +0000)
handling of cases where one or both branches of the conditional
have void type, i.e. throw an exception or don't return.
(fold): Only apply (and undo) type conversion to the non-void
branches of a COND_EXPR.

* f/com.c (ffecom_subscript_check_): Cast the failure branch
of the bounds check COND_EXPR to void, to indicate noreturn.
(ffe_truthvalue_conversion): Only apply truth value conversion
to the non-void branches of a COND_EXPR.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@58661 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/f/ChangeLog
gcc/f/com.c
gcc/fold-const.c

index 3ced87b..c0798df 100644 (file)
@@ -1,3 +1,11 @@
+2002-10-30  Roger Sayle  <roger@eyesopen.com>
+
+       * fold-const.c (fold_binary_op_with_conditional_arg):  Improve
+       handling of cases where one or both branches of the conditional
+       have void type, i.e. throw an exception or don't return.
+       (fold): Only apply (and undo) type conversion to the non-void
+       branches of a COND_EXPR.
+
 2002-10-30  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/8333
index 2e03cb8..58ef012 100644 (file)
@@ -1,3 +1,10 @@
+2002-10-30  Roger Sayle  <roger@eyesopen.com>
+
+       * com.c (ffecom_subscript_check_): Cast the failure branch
+       of the bounds check COND_EXPR to void, to indicate noreturn.
+       (ffe_truthvalue_conversion): Only apply truth value conversion
+       to the non-void branches of a COND_EXPR.
+
 2002-10-26  Andris Pavenis  <pavenis@latnet.lv>
 
        * lang-specs.h: Fix ratfor specs.
index cc3af7e..1e066f5 100644 (file)
@@ -806,6 +806,7 @@ ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims,
   die = ffecom_call_gfrt (FFECOM_gfrtRANGE,
                          args, NULL_TREE);
   TREE_SIDE_EFFECTS (die) = 1;
+  die = convert (void_type_node, die);
 
   element = ffecom_3 (COND_EXPR,
                      TREE_TYPE (element),
@@ -14772,10 +14773,17 @@ ffe_truthvalue_conversion (expr)
        return ffe_truthvalue_conversion (TREE_OPERAND (expr, 0));
 
     case COND_EXPR:
-      /* Distribute the conversion into the arms of a COND_EXPR.  */
-      return fold (build (COND_EXPR, integer_type_node, TREE_OPERAND (expr, 0),
-                         ffe_truthvalue_conversion (TREE_OPERAND (expr, 1)),
-                         ffe_truthvalue_conversion (TREE_OPERAND (expr, 2))));
+      {
+       /* Distribute the conversion into the arms of a COND_EXPR.  */
+       tree arg1 = TREE_OPERAND (expr, 1);
+       tree arg2 = TREE_OPERAND (expr, 2);
+       if (! VOID_TYPE_P (TREE_TYPE (arg1)))
+         arg1 = ffe_truthvalue_conversion (arg1);
+       if (! VOID_TYPE_P (TREE_TYPE (arg2)))
+         arg2 = ffe_truthvalue_conversion (arg2);
+       return fold (build (COND_EXPR, integer_type_node,
+                           TREE_OPERAND (expr, 0), arg1, arg2));
+      }
 
     case CONVERT_EXPR:
       /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
index 5f5e25f..c08d44e 100644 (file)
@@ -4456,15 +4456,23 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
         we simply build `a, throw 3'.  */
       if (VOID_TYPE_P (TREE_TYPE (true_value)))
        {
-         lhs_code = COMPOUND_EXPR;
-         if (!cond_first_p)
-           lhs_type = void_type_node;
+         if (! cond_first_p)
+           {
+             lhs_code = COMPOUND_EXPR;
+             lhs_type = void_type_node;
+           }
+         else
+           lhs = true_value;
        }
       if (VOID_TYPE_P (TREE_TYPE (false_value)))
        {
-         rhs_code = COMPOUND_EXPR;
-         if (!cond_first_p)
-           rhs_type = void_type_node;
+         if (! cond_first_p)
+           {
+             rhs_code = COMPOUND_EXPR;
+             rhs_type = void_type_node;
+           }
+         else
+           rhs = false_value;
        }
     }
   else
@@ -4491,7 +4499,8 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
 
   if (TREE_CODE (arg) == SAVE_EXPR)
     save = 1;
-  else if (!TREE_CONSTANT (arg)
+  else if (lhs == 0 && rhs == 0
+          && !TREE_CONSTANT (arg)
           && (*lang_hooks.decls.global_bindings_p) () == 0
           && ((TREE_CODE (arg) != VAR_DECL && TREE_CODE (arg) != PARM_DECL)
               || TREE_SIDE_EFFECTS (arg)))
@@ -4726,9 +4735,14 @@ fold (expr)
                      fold (build1 (code, type, TREE_OPERAND (arg0, 1))));
       else if (TREE_CODE (arg0) == COND_EXPR)
        {
+         tree arg01 = TREE_OPERAND (arg0, 1);
+         tree arg02 = TREE_OPERAND (arg0, 2);
+         if (! VOID_TYPE_P (TREE_TYPE (arg01)))
+           arg01 = fold (build1 (code, type, arg01));
+         if (! VOID_TYPE_P (TREE_TYPE (arg02)))
+           arg02 = fold (build1 (code, type, arg02));
          t = fold (build (COND_EXPR, type, TREE_OPERAND (arg0, 0),
-                          fold (build1 (code, type, TREE_OPERAND (arg0, 1))),
-                          fold (build1 (code, type, TREE_OPERAND (arg0, 2)))));
+                          arg01, arg02));
 
          /* If this was a conversion, and all we did was to move into
             inside the COND_EXPR, bring it back out.  But leave it if
@@ -4744,6 +4758,8 @@ fold (expr)
              && TREE_CODE (t) == COND_EXPR
              && TREE_CODE (TREE_OPERAND (t, 1)) == code
              && TREE_CODE (TREE_OPERAND (t, 2)) == code
+             && ! VOID_TYPE_P (TREE_OPERAND (t, 1))
+             && ! VOID_TYPE_P (TREE_OPERAND (t, 2))
              && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0))
                  == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 2), 0)))
              && ! (INTEGRAL_TYPE_P (TREE_TYPE (t))