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]

[PATCH] Handle BOOLEAN_TYPEs in common_type


On Mon, 16 May 2005, Joseph S. Myers wrote:
> c_common_type has a well-defined interface.  common_type is a kludge
> wrapping around that to deal with the requirements of shorten_compare.
> So I think common_type is the right place.

Thanks.  The following revision implements this suggestion of placing
this logic in common_type.  Now that the relationship between common_type
and c_common_type has been explained, I agree this is the more appropriate
location.

The following patch has been tested on x86_64-unknown-linux-gnu with a
full "make bootstrap", and regression tested with a top-level "make -k
check" with no new failures.  I've also confirmed that this patch cures
the failure I was seeing.

Ok for mainline?



2005-05-16  Roger Sayle  <roger@eyesopen.com>

	* c-typeck.c (common_type): Also handle BOOLEAN_TYPEs.


Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.441
diff -c -3 -p -r1.441 c-typeck.c
*** c-typeck.c	10 May 2005 13:46:38 -0000	1.441
--- c-typeck.c	16 May 2005 23:23:37 -0000
*************** c_common_type (tree t1, tree t2)
*** 618,624 ****
  }

  /* Wrapper around c_common_type that is used by c-common.c.  ENUMERAL_TYPEs
!    are allowed here and are converted to their compatible integer types.  */
  tree
  common_type (tree t1, tree t2)
  {
--- 618,626 ----
  }

  /* Wrapper around c_common_type that is used by c-common.c.  ENUMERAL_TYPEs
!    are allowed here and are converted to their compatible integer types.
!    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
!    preferably a non-Boolean type as the common type.  */
  tree
  common_type (tree t1, tree t2)
  {
*************** common_type (tree t1, tree t2)
*** 626,631 ****
--- 628,645 ----
      t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
    if (TREE_CODE (t2) == ENUMERAL_TYPE)
      t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
+
+   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
+   if (TREE_CODE (t1) == BOOLEAN_TYPE
+       && TREE_CODE (t2) == BOOLEAN_TYPE)
+     return boolean_type_node;
+
+   /* If either type is BOOLEAN_TYPE, then return the other.  */
+   if (TREE_CODE (t1) == BOOLEAN_TYPE)
+     return t2;
+   if (TREE_CODE (t2) == BOOLEAN_TYPE)
+     return t1;
+
    return c_common_type (t1, t2);
  }



Roger
--


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