re PR c/3444 (Test fails (cast))

PR c/3444:
	* c-typeck.c (build_binary_op) [BIT_XOR_EXPR]: Remove explicit
	shortening.

	* typeck.c (build_binary_op) [BIT_XOR_EXPR]: Remove explicit
	shortening.

	* gcc.c-torture/execute/20020216-1.c: New test.

From-SVN: r49825
This commit is contained in:
Jakub Jelinek 2002-02-17 21:47:52 +01:00 committed by Jakub Jelinek
parent e16b32fc25
commit f6f8ada39a
6 changed files with 39 additions and 48 deletions

View File

@ -1,3 +1,9 @@
2002-02-17 Jakub Jelinek <jakub@redhat.com>
PR c/3444:
* c-typeck.c (build_binary_op) [BIT_XOR_EXPR]: Remove explicit
shortening.
2002-02-17 Philipp Thomas <pthomas@suse.de>
* config/cris/cris.h: Undefine STARTFILE_SPEC and

View File

@ -2060,29 +2060,6 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
case BIT_XOR_EXPR:
if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
shorten = -1;
/* If one operand is a constant, and the other is a short type
that has been converted to an int,
really do the work in the short type and then convert the
result to int. If we are lucky, the constant will be 0 or 1
in the short type, making the entire operation go away. */
if (TREE_CODE (op0) == INTEGER_CST
&& TREE_CODE (op1) == NOP_EXPR
&& TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
{
final_type = result_type;
op1 = TREE_OPERAND (op1, 0);
result_type = TREE_TYPE (op1);
}
if (TREE_CODE (op1) == INTEGER_CST
&& TREE_CODE (op0) == NOP_EXPR
&& TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
{
final_type = result_type;
op0 = TREE_OPERAND (op0, 0);
result_type = TREE_TYPE (op0);
}
break;
case TRUNC_MOD_EXPR:

View File

@ -1,3 +1,8 @@
2002-02-17 Jakub Jelinek <jakub@redhat.com>
* typeck.c (build_binary_op) [BIT_XOR_EXPR]: Remove explicit
shortening.
2002-02-15 Nathan Sidwell <nathan@codesourcery.com>
* decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs,

View File

@ -3514,31 +3514,6 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
case BIT_XOR_EXPR:
if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
shorten = -1;
/* If one operand is a constant, and the other is a short type
that has been converted to an int,
really do the work in the short type and then convert the
result to int. If we are lucky, the constant will be 0 or 1
in the short type, making the entire operation go away. */
if (TREE_CODE (op0) == INTEGER_CST
&& TREE_CODE (op1) == NOP_EXPR
&& (TYPE_PRECISION (type1)
> TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0))))
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
{
final_type = result_type;
op1 = TREE_OPERAND (op1, 0);
result_type = TREE_TYPE (op1);
}
if (TREE_CODE (op1) == INTEGER_CST
&& TREE_CODE (op0) == NOP_EXPR
&& (TYPE_PRECISION (type0)
> TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))))
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
{
final_type = result_type;
op0 = TREE_OPERAND (op0, 0);
result_type = TREE_TYPE (op0);
}
break;
case TRUNC_MOD_EXPR:

View File

@ -1,3 +1,7 @@
2002-02-17 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/execute/20020216-1.c: New test.
2002-02-16 Neil Booth <neil@daikokuya.demon.co.uk>
* gcc.dg/decl-1.c: Update, new test.

View File

@ -0,0 +1,24 @@
/* PR c/3444
This used to fail because bitwise xor was improperly computed in char type
and sign extended to int type. */
extern void abort ();
extern void exit (int);
signed char c = (signed char) 0xffffffff;
int foo (void)
{
return (unsigned short) c ^ (signed char) 0x99999999;
}
int main (void)
{
if ((unsigned char) -1 != 0xff
|| sizeof (short) != 2
|| sizeof (int) != 4)
exit (0);
if (foo () != (int) 0xffff0066)
abort ();
exit (0);
}