re PR c/3444 (Test fails (cast))
authorJakub Jelinek <jakub@redhat.com>
Sun, 17 Feb 2002 20:47:52 +0000 (21:47 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sun, 17 Feb 2002 20:47:52 +0000 (21:47 +0100)
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
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20020216-1.c [new file with mode: 0644]

index 0e5ed7acddc832d324e75b71755b22fa88f0d8f9..700f7a479adaa87e3ad20d8fdcaf2480da17c3d7 100644 (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
index 3e00e04b48b294b166d1403a16b92e31465bcdb5..dd8abdd11f75181e787a39176daa99e72dc901b5 100644 (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:
index b8f762830cdd246e450617a1544930a193d3c86d..872ad4f4113e1ba38f2e08aa2488b7baa3fa22fa 100644 (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,
index 4d0cf786ecf0b64c80d245fa58a2deb0819982e9..62d17a8cfd94e7fbecb71f4776ba80dcbda25471 100644 (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:
index 48bc0e15ad1f63e0c52d76ac0e6c4d2d704922bb..1e1538de6f6340cb5b6d0299402e3cab17819b8d 100644 (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.
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 (file)
index 0000000..bf62de5
--- /dev/null
@@ -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);
+}