This is the mail archive of the gcc-patches@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]

fix bit test type problem


Found this via miscompilation on tree-ssa branch.

We don't mind type semantics properly during the manipulation,
which leads to TREE_OVERFLOW being set when it shouldn't be.


r~


        * fold-const.c (fold_single_bit_test): Convert the input to the
        operational intermediate type.

Index: gcc/fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.54
diff -u -p -u -r1.213.2.54 fold-const.c
--- gcc/fold-const.c	24 Oct 2003 23:45:35 -0000	1.213.2.54
+++ gcc/fold-const.c	30 Oct 2003 02:12:29 -0000
@@ -5022,7 +5022,7 @@ fold_single_bit_test (enum tree_code cod
       int bitnum = tree_log2 (TREE_OPERAND (arg0, 1));
       enum machine_mode operand_mode = TYPE_MODE (type);
       int ops_unsigned;
-      tree signed_type, unsigned_type;
+      tree signed_type, unsigned_type, intermediate_type;
       tree arg00;
   
       /* If we have (A & C) != 0 where C is the sign bit of A, convert
@@ -5068,22 +5068,23 @@ fold_single_bit_test (enum tree_code cod
 
       signed_type = (*lang_hooks.types.type_for_mode) (operand_mode, 0);
       unsigned_type = (*lang_hooks.types.type_for_mode) (operand_mode, 1);
+      intermediate_type = ops_unsigned ? unsigned_type : signed_type;
+      inner = convert (intermediate_type, inner);
 
       if (bitnum != 0)
-	inner = build (RSHIFT_EXPR, ops_unsigned ? unsigned_type : signed_type,
+	inner = build (RSHIFT_EXPR, intermediate_type,
 		       inner, size_int (bitnum));
 
       if (code == EQ_EXPR)
-	inner = build (BIT_XOR_EXPR, ops_unsigned ? unsigned_type : signed_type,
+	inner = build (BIT_XOR_EXPR, intermediate_type,
 		       inner, integer_one_node);
 
       /* Put the AND last so it can combine with more things.  */
-      inner = build (BIT_AND_EXPR, ops_unsigned ? unsigned_type : signed_type,
+      inner = build (BIT_AND_EXPR, intermediate_type,
 		     inner, integer_one_node);
 
       /* Make sure to return the proper type.  */
-      if (TREE_TYPE (inner) != result_type)
-	inner = convert (result_type, inner);
+      inner = convert (result_type, inner);
 
       return inner;
     }


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