From f6f8ada39ab16554f222bdc0a84a44689a44cc36 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sun, 17 Feb 2002 21:47:52 +0100 Subject: [PATCH] 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 --- gcc/ChangeLog | 6 +++++ gcc/c-typeck.c | 23 ----------------- gcc/cp/ChangeLog | 5 ++++ gcc/cp/typeck.c | 25 ------------------- gcc/testsuite/ChangeLog | 4 +++ .../gcc.c-torture/execute/20020216-1.c | 24 ++++++++++++++++++ 6 files changed, 39 insertions(+), 48 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/20020216-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0e5ed7acddc..700f7a479ad 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-02-17 Jakub Jelinek + + PR c/3444: + * c-typeck.c (build_binary_op) [BIT_XOR_EXPR]: Remove explicit + shortening. + 2002-02-17 Philipp Thomas * config/cris/cris.h: Undefine STARTFILE_SPEC and diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 3e00e04b48b..dd8abdd11f7 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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: diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b8f762830cd..872ad4f4113 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2002-02-17 Jakub Jelinek + + * typeck.c (build_binary_op) [BIT_XOR_EXPR]: Remove explicit + shortening. + 2002-02-15 Nathan Sidwell * decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs, diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 4d0cf786ecf..62d17a8cfd9 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 48bc0e15ad1..1e1538de6f6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-02-17 Jakub Jelinek + + * gcc.c-torture/execute/20020216-1.c: New test. + 2002-02-16 Neil Booth * gcc.dg/decl-1.c: Update, new test. diff --git a/gcc/testsuite/gcc.c-torture/execute/20020216-1.c b/gcc/testsuite/gcc.c-torture/execute/20020216-1.c new file mode 100644 index 00000000000..bf62de568e4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20020216-1.c @@ -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); +}