PATCH: Trunk miscompiles libjava

Andrew Haley aph@cambridge.redhat.com
Fri May 24 11:31:00 GMT 2002


This patch:

date: 2002/04/18 10:39:20;  author: jakub;  state: Exp;  lines: +43 -0
	* fold-const.c (fold) [NOP_EXPR]: Convert (T)(x&c) into ((T)x&(T)c)
	for integer constant c (if x has unsigned type or sign bit is not
	set in c).  This folds the zero/sign extension into the bit-wise and
	operation.

	* gcc.c-torture/compile/20020415-1.c: New.

isn't right when T is bool.

(bool) N == (N != 0)

so

(bool)(2&1) != (bool)2 & (bool)1

2002-05-24  Andrew Haley  <aph@redhat.com>

	* fold-const.c (fold): Don't convert (T)(x & c) into (T)x & (T)c
	if T is a boolean type.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.203
diff -u -r1.203 fold-const.c
--- fold-const.c	17 May 2002 18:07:00 -0000	1.203
+++ fold-const.c	24 May 2002 17:40:07 -0000
@@ -4784,6 +4784,7 @@
 	 constants (if x has signed type, the sign bit cannot be set
 	 in c).  This folds extension into the BIT_AND_EXPR.  */
       if (INTEGRAL_TYPE_P (TREE_TYPE (t))
+	  && TREE_CODE (TREE_TYPE (t)) != BOOLEAN_TYPE
 	  && TREE_CODE (TREE_OPERAND (t, 0)) == BIT_AND_EXPR
 	  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 1)) == INTEGER_CST)
 	{

Andrew.



More information about the Gcc-patches mailing list