This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: PR 19650


This is due to a problem in folding. fold() is given this:

<mult_expr 0x77d150
type <integer_type 0x4240c400 long unsigned int public unsigned sizetype SI
arg 0 <nop_expr 0x77fd80 type <integer_type 0x4240c400 long unsigned int>
arg 0 <eq_expr 0x77dcf0 type <boolean_type 0x4240ca80 bool>
arg 0 <var_decl 0x77a280>
arg 1 <integer_cst 0x424dcda0 constant invariant 2>>>
arg 1 <integer_cst 0x4240e380 4>>


which gets into the optimization in fold_binary_op_with_conditional_arg, which asks fold to do this:

<mult_expr 0x73e180
type <integer_type 0x4240c400 long unsigned int public unsigned sizetype SI
constant invariant
arg 0 <integer_cst 0x4240e9a0 type <boolean_type 0x4240ca80 bool> constant invariant 1>
arg 1 <integer_cst 0x4240e380 4>>


which gets evaluated in type boolean, resulting in 0 rather than 4. I'm not sure where in the twisty
little passages this should be fixed, but fold_binary_op_with_conditional_arg is taking a type
from the EQ_EXPR, even though that should always be boolean (right)? Which is suspicious,
and I'm inclined to think it should be using the input type instead. Like this:


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.497
diff -u -d -b -w -p -r1.497 fold-const.c
--- fold-const.c        23 Jan 2005 15:05:29 -0000      1.497
+++ fold-const.c        27 Jan 2005 22:45:48 -0000
@@ -5412,10 +5412,10 @@ fold_binary_op_with_conditional_arg (enu
     }
   else
     {
-      tree testtype = TREE_TYPE (cond);
+      /*tree testtype = TREE_TYPE (cond);*/
       test = cond;
-      true_value = constant_boolean_node (true, testtype);
-      false_value = constant_boolean_node (false, testtype);
+      true_value = constant_boolean_node (true, /*test*/type);
+      false_value = constant_boolean_node (false, /*test*/type);
     }

if (lhs == 0)

Does this look like the right approach?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]