[PATCH][C++] Make __java_boolean a true bool (PR 33887)

Richard Guenther rguenther@suse.de
Tue Jan 29 14:58:00 GMT 2008


On Tue, 29 Jan 2008, Andrew Haley wrote:

> Andrew Pinski wrote:
> > On 1/29/08, Richard Guenther <rguenther@suse.de> wrote:
> > > ppc64-linux -m32/-m64 seem to be fine:
> > > As I don't see how boolean type can be darwin specific, I need your
> > > help in tracking it down.  Note that without this patch in you will now
> > > get abort for
> > 
> > The issue is that on PPC darwin, sizeof of _Bool and bool was 4 bytes
> > while jboolean was 1 byte.  So now we got an ABI difference between
> > the java front-end and C++ front-end which still says bool is 1 byte
> > but the C++ front-end says jboolean is 4 bytes.
> 
> Okay.  Is the problem that the compiler assumes all data types with
> boolean semantics are the same size?  That, if bool is 4 bytes long, so
> must jboolean?

I will test the following.  Andreas, can you give it a try on
ppc-darwin?

Thanks,
Richard.

2008-01-29  Richard Guenther  <rguenther@suse.de>

	Revert
	PR c++/33887
	* decl.c (record_builtin_java_type): Make __java_boolean
	a variant of bool.
	* typeck.c (structural_comptypes): Move TYPE_FOR_JAVA check
	after TYPE_MAIN_VARIANT check.

	* typeck.c (build_unary_op): Reject -- on all boolean types.
	* decl.c (record_builtin_java_type): Make __java_boolean
	a BOOLEAN_TYPE.
	* cvt.c (type_promotes_to): All BOOLEAN_TYPEs promote to int.
	* mangle.c (write_template_arg_literal): All BOOLEAN_TYPE
	constants should be either one or zero.

Index: typeck.c
===================================================================
*** typeck.c	(revision 131937)
--- typeck.c	(working copy)
*************** structural_comptypes (tree t1, tree t2, 
*** 962,967 ****
--- 962,969 ----
    if (TREE_CODE (t1) != ARRAY_TYPE
        && TYPE_QUALS (t1) != TYPE_QUALS (t2))
      return false;
+   if (TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
+     return false;
  
    /* Allow for two different type nodes which have essentially the same
       definition.  Note that we already checked for equality of the type
*************** structural_comptypes (tree t1, tree t2, 
*** 971,979 ****
        && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
      return true;
  
-   if (TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
-     return false;
- 
    /* Compare the types.  Break out if they could be the same.  */
    switch (TREE_CODE (t1))
      {
--- 973,978 ----
*************** build_unary_op (enum tree_code code, tre
*** 4293,4299 ****
  	  return error_mark_node;
  
  	/* Forbid using -- on `bool'.  */
! 	if (same_type_p (declared_type, boolean_type_node))
  	  {
  	    if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
  	      {
--- 4292,4298 ----
  	  return error_mark_node;
  
  	/* Forbid using -- on `bool'.  */
! 	if (TREE_CODE (declared_type) == BOOLEAN_TYPE)
  	  {
  	    if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
  	      {
Index: decl.c
===================================================================
*** decl.c	(revision 131937)
--- decl.c	(working copy)
*************** record_builtin_java_type (const char* na
*** 3161,3167 ****
      type = make_signed_type (size);
    else if (size == -1)
      { /* "__java_boolean".  */
!       type = build_variant_type_copy (boolean_type_node);
      }
    else if (size > -32)
      { /* "__java_char".  */
--- 3161,3168 ----
      type = make_signed_type (size);
    else if (size == -1)
      { /* "__java_boolean".  */
!       type = make_unsigned_type (1);
!       TREE_SET_CODE (type) = BOOLEAN_TYPE;
      }
    else if (size > -32)
      { /* "__java_char".  */
Index: cvt.c
===================================================================
*** cvt.c	(revision 131937)
--- cvt.c	(working copy)
*************** type_promotes_to (tree type)
*** 1204,1210 ****
  
    /* bool always promotes to int (not unsigned), even if it's the same
       size.  */
!   if (type == boolean_type_node)
      type = integer_type_node;
  
    /* Normally convert enums to int, but convert wide enums to something
--- 1204,1210 ----
  
    /* bool always promotes to int (not unsigned), even if it's the same
       size.  */
!   if (TREE_CODE (type) == BOOLEAN_TYPE)
      type = integer_type_node;
  
    /* Normally convert enums to int, but convert wide enums to something
Index: mangle.c
===================================================================
*** mangle.c	(revision 131937)
--- mangle.c	(working copy)
*************** write_template_arg_literal (const tree v
*** 2293,2299 ****
        break;
  
      case INTEGER_CST:
!       gcc_assert (!same_type_p (TREE_TYPE (value), boolean_type_node)
  		  || integer_zerop (value) || integer_onep (value));
        write_integer_cst (value);
        break;
--- 2293,2299 ----
        break;
  
      case INTEGER_CST:
!       gcc_assert (TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
  		  || integer_zerop (value) || integer_onep (value));
        write_integer_cst (value);
        break;



More information about the Gcc-patches mailing list