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]

[C++ PATCH] Remove references to TYPE_IS_SIZETYPE


This patch is another installment in my long term project of cleaning
up overflow handling in trees.  One aspect of that clean-up, based on
a very long and complicated set of dependenices, is the middle-end's
notion of types that are maked as sizetypes, TYPE_IS_SIZETYPE.  These
are internal types that aren't/shouldn't be visible to user's source
code, are used in the middle-end for tracking the sizes of objects.
Particularly interesting is that these types, are sign-extended even
though unsigned, and have curious overflow behaviour.

It turns out that most front-ends, including fortran, java and ada
are content to be oblivious to this peculiar implementation wart.
One exception, however, is the C++ front-end which refers to the
TYPE_IS_SIZETYPE macro in a few places.  Whilst the special case
handling of sizetype in comptypes may have served a purpose once
upon a time, the only remaining utility is cover-up a minor wart...

When testing whether a class has a two-argument delete implementation, the
front-end needs to confirm that the type of the second argument is the
same type as size_t.  However, instead of checking against size_type_node
which is the user-visible type corresponding to size_t, the front-end
code actually compares against the internal hidden type sizetype.
Normally same_type_p would always fail, but some special case code
in comptypes, spots the use of a TYPE_IS_SIZETYPE type and performs
the checks on the user-visible type instead.  It turns out that if
we correctly compare against size_type_node to begin with, all the
special casing of TYPE_IS_SIZETYPE can go away.  The rest of the
front-end is well behaved and able to keep the internal types and the
user types distinct.

These C++ parts have been split out as being independent from a larger
patch to completely remove the TYPE_IS_SIZETYPE distinction from the
middle-end.  The patch below has been tested on i686-pc-linux-gnu,
with a full "make bootstrap", all default languages, and regression
tested with a top-level "make -k check" with no new failures.

Ok for mainline?



2006-11-02  Roger Sayle  <roger@eyesopen.com>

	* call.c (build_op_delete_call): Test user-visible type against
	size_type_node, instead of against the internal type, sizetype.
	* class.c (type_requires_array_cookie): Likewise.
	* mangle.c (write_builtin_type) <INTEGER_TYPE>: Remove special
	handling of TYPE_IS_SIZETYPE.
	* typeck.c (type_after_usual_arithmetic_conversions): Remove
	special case handling of TYPE_IS_SIZETYPE.
	(comptypes): Likewise.


Index: call.c
===================================================================
*** call.c	(revision 118200)
--- call.c	(working copy)
*************** build_op_delete_call (enum tree_code cod
*** 4077,4083 ****
  	  /* On the second pass, the second argument must be
  	     "size_t".  */
  	  else if (pass == 1
! 		   && same_type_p (TREE_VALUE (t), sizetype)
  		   && TREE_CHAIN (t) == void_list_node)
  	    break;
  	}
--- 4077,4083 ----
  	  /* On the second pass, the second argument must be
  	     "size_t".  */
  	  else if (pass == 1
! 		   && same_type_p (TREE_VALUE (t), size_type_node)
  		   && TREE_CHAIN (t) == void_list_node)
  	    break;
  	}
Index: class.c
===================================================================
*** class.c	(revision 118200)
--- class.c	(working copy)
*************** type_requires_array_cookie (tree type)
*** 4050,4056 ****
  	 argument is `size_t', it will be the usual deallocation
  	 function -- unless there is one-argument function, too.  */
        if (TREE_CHAIN (second_parm) == void_list_node
! 	  && same_type_p (TREE_VALUE (second_parm), sizetype))
  	has_two_argument_delete_p = true;
      }

--- 4050,4056 ----
  	 argument is `size_t', it will be the usual deallocation
  	 function -- unless there is one-argument function, too.  */
        if (TREE_CHAIN (second_parm) == void_list_node
! 	  && same_type_p (TREE_VALUE (second_parm), size_type_node))
  	has_two_argument_delete_p = true;
      }

Index: mangle.c
===================================================================
*** mangle.c	(revision 118200)
--- mangle.c	(working copy)
*************** write_builtin_type (tree type)
*** 1732,1741 ****
        break;

      case INTEGER_TYPE:
-       /* If this is size_t, get the underlying int type.  */
-       if (TYPE_IS_SIZETYPE (type))
- 	type = TYPE_DOMAIN (type);
-
        /* TYPE may still be wchar_t, since that isn't in
  	 integer_type_nodes.  */
        if (type == wchar_type_node)
--- 1732,1737 ----
Index: typeck.c
===================================================================
*** typeck.c	(revision 118200)
--- typeck.c	(working copy)
*************** type_after_usual_arithmetic_conversions
*** 324,335 ****

    if (code1 != REAL_TYPE)
      {
-       /* If one is a sizetype, use it so size_binop doesn't blow up.  */
-       if (TYPE_IS_SIZETYPE (t1) > TYPE_IS_SIZETYPE (t2))
- 	return build_type_attribute_variant (t1, attributes);
-       if (TYPE_IS_SIZETYPE (t2) > TYPE_IS_SIZETYPE (t1))
- 	return build_type_attribute_variant (t2, attributes);
-
        /* If one is unsigned long long, then convert the other to unsigned
  	 long long.  */
        if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_unsigned_type_node)
--- 324,329 ----
*************** comptypes (tree t1, tree t2, int strict)
*** 966,981 ****
  	t2 = resolved;
      }

-   /* If either type is the internal version of sizetype, use the
-      language version.  */
-   if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
-       && TYPE_ORIG_SIZE_TYPE (t1))
-     t1 = TYPE_ORIG_SIZE_TYPE (t1);
-
-   if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
-       && TYPE_ORIG_SIZE_TYPE (t2))
-     t2 = TYPE_ORIG_SIZE_TYPE (t2);
-
    if (TYPE_PTRMEMFUNC_P (t1))
      t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
    if (TYPE_PTRMEMFUNC_P (t2))
--- 960,965 ----


Roger
--


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