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] remove the unsigned_type language hook


The attached patch removes the remaining parts of the unsigned_type
language hook. It depends on my previous patch that adds a default
implementation.

Compiled and regression tested with all languages (including ada).

OK for trunk?

gcc/ada/ChangeLog
* gcc/ada/gigi.h (gnat_unsigned_type): Remove.
* gcc/ada/misc.c (LANG_HOOKS_UNSIGNED_TYPE): Remove.
* gcc/ada/trans.c (gnat_to_gnu): Use get_unsigned_type instead of
gnat_unsigned_type.
                          (convert_with_check): Likewise.
* gcc/ada/utils.c (gnat_unsigned_type): Remove.

gcc/ChangeLog
* gcc/c-common.c (warnings_for_convert_and_check): Use
get_unsigned_type instead of c_common_unsigned_type
                           (c_common_unsigned_type): Remove.
                           (shorten_compare): Use
c_common_signed_or_unsigned_type instead of c_common_unsigned_type.
                          (c_common_nodes_and_builtins): Use
get_unsigned_type instead of c_common_unsigned_type.
* gcc/c-common.h (c_common_unsigned_type): Remove.
* gcc/c-decl.c (grokdeclarator): Use c_common_unsigned_type instead
of get_unsigned_type.
* gcc/c-format.c (check_format_types): Likewise.
* gcc/c-objc-common.h (LANG_HOOKS_UNSIGNED_TYPE): Remove.
* gcc/c-typeck.c (convert_for_assignment): Use get_unsigned_type
instead of c_common_unsigned_type.
* gcc/convert.c (convert_to_integer): Likewise.
* gcc/expmed.c (make_tree): Use get_unsigned_type instead of
lang_hooks.types.unsigned_type.
* gcc/fold-const.c (fold_negate_expr): Likewise.
                          (build_range_check): Likewise.
                          (fold_unary): Likewise.
                          (fold_binary): Likewise.
                          (fold_ternary): Likewise.
* gcc/langhooks-def.h (LANG_HOOKS_UNSIGNED_TYPE): Remove.
                                (LANG_HOOKS_FOR_TYPES_INITIALIZER):
Remove LANG_HOOKS_UNSIGNED_TYPE.
* gcc/langhooks.h (lang_hooks_for_types): Remove unsigned_type
* gcc/tree.c (unsigned_type_for): Use get_unsigned_type instead of
lang_hooks.types.unsigned_type

gcc/cp/ChangeLog
* gcc/cp/cp-objcp-common.h (LANG_HOOKS_UNSIGNED_TYPE): Remove.
* gcc/cp/decl.c (grokdeclarator): Replace c_common_unsigned_type with
get_unsigned_type.

--
Rafael Avila de Espindola

Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland

Registered in Dublin, Ireland
Registration Number: 368047
=== gcc/ada/gigi.h
==================================================================
--- gcc/ada/gigi.h	(revision 124112)
+++ gcc/ada/gigi.h	(local)
@@ -448,9 +448,6 @@
 /* Emit debug info for all global variable declarations.  */
 extern void gnat_write_global_declarations (void);
 
-/* Return the unsigned version of a TYPE_NODE, a scalar type.  */
-extern tree gnat_unsigned_type (tree type_node);
-
 /* Return the signed version of a TYPE_NODE, a scalar type.  */
 extern tree gnat_signed_type (tree type_node);
 
=== gcc/ada/misc.c
==================================================================
--- gcc/ada/misc.c	(revision 124112)
+++ gcc/ada/misc.c	(local)
@@ -159,8 +159,6 @@
 #define LANG_HOOKS_TYPE_FOR_SIZE	gnat_type_for_size
 #undef  LANG_HOOKS_SIGNED_TYPE
 #define LANG_HOOKS_SIGNED_TYPE		gnat_signed_type
-#undef  LANG_HOOKS_UNSIGNED_TYPE
-#define LANG_HOOKS_UNSIGNED_TYPE	gnat_unsigned_type
 #undef  LANG_HOOKS_ATTRIBUTE_TABLE
 #define LANG_HOOKS_ATTRIBUTE_TABLE	gnat_internal_attribute_table
 #undef  LANG_HOOKS_BUILTIN_FUNCTION
=== gcc/ada/trans.c
==================================================================
--- gcc/ada/trans.c	(revision 124112)
+++ gcc/ada/trans.c	(local)
@@ -3484,7 +3484,7 @@
 	if (Nkind (gnat_node) == N_Op_Shift_Right
 	    && !TYPE_UNSIGNED (gnu_type))
 	  {
-	    gnu_type = gnat_unsigned_type (gnu_type);
+	    gnu_type = get_unsigned_type (gnu_type);
 	    ignore_lhs_overflow = true;
 	  }
 	else if (Nkind (gnat_node) == N_Op_Shift_Right_Arithmetic
@@ -5538,13 +5538,13 @@
 
       if (INTEGRAL_TYPE_P (gnu_in_basetype)
 	  && !TYPE_UNSIGNED (gnu_in_basetype))
-	gnu_in_ub = convert (gnat_unsigned_type (gnu_in_basetype), gnu_in_ub);
+	gnu_in_ub = convert (get_unsigned_type (gnu_in_basetype), gnu_in_ub);
 
       if (INTEGRAL_TYPE_P (gnu_base_type) && TYPE_UNSIGNED (gnu_base_type))
 	gnu_out_lb = convert (gnat_signed_type (gnu_base_type), gnu_out_lb);
 
       if (INTEGRAL_TYPE_P (gnu_base_type) && !TYPE_UNSIGNED (gnu_base_type))
-	gnu_out_ub = convert (gnat_unsigned_type (gnu_base_type), gnu_out_ub);
+	gnu_out_ub = convert (get_unsigned_type (gnu_base_type), gnu_out_ub);
 
       /* Check each bound separately and only if the result bound
 	 is tighter than the bound on the input type.  Note that all the
=== gcc/ada/utils.c
==================================================================
--- gcc/ada/utils.c	(revision 124112)
+++ gcc/ada/utils.c	(local)
@@ -2290,29 +2290,6 @@
     return NULL_TREE;
 }
 
-/* Return the unsigned version of a TYPE_NODE, a scalar type.  */
-
-tree
-gnat_unsigned_type (tree type_node)
-{
-  tree type = gnat_type_for_size (TYPE_PRECISION (type_node), 1);
-
-  if (TREE_CODE (type_node) == INTEGER_TYPE && TYPE_MODULAR_P (type_node))
-    {
-      type = copy_node (type);
-      TREE_TYPE (type) = type_node;
-    }
-  else if (TREE_TYPE (type_node)
-	   && TREE_CODE (TREE_TYPE (type_node)) == INTEGER_TYPE
-	   && TYPE_MODULAR_P (TREE_TYPE (type_node)))
-    {
-      type = copy_node (type);
-      TREE_TYPE (type) = TREE_TYPE (type_node);
-    }
-
-  return type;
-}
-
 /* Return the signed version of a TYPE_NODE, a scalar type.  */
 
 tree
=== gcc/c-common.c
==================================================================
--- gcc/c-common.c	(revision 124112)
+++ gcc/c-common.c	(local)
@@ -1303,7 +1303,7 @@
           else if (warn_conversion)
             conversion_warning (type, expr);
         }
-      else if (!int_fits_type_p (expr, c_common_unsigned_type (type))) 
+      else if (!int_fits_type_p (expr, get_unsigned_type (type))) 
 	warning (OPT_Woverflow,
 		 "overflow in implicit constant conversion");
       /* No warning for converting 0x80000000 to int.  */
@@ -1998,39 +1998,6 @@
   return 0;
 }
 
-/* Return an unsigned type the same as TYPE in other respects.  */
-tree
-c_common_unsigned_type (tree type)
-{
-  tree type1 = TYPE_MAIN_VARIANT (type);
-  if (type1 == signed_char_type_node || type1 == char_type_node)
-    return unsigned_char_type_node;
-  if (type1 == integer_type_node)
-    return unsigned_type_node;
-  if (type1 == short_integer_type_node)
-    return short_unsigned_type_node;
-  if (type1 == long_integer_type_node)
-    return long_unsigned_type_node;
-  if (type1 == long_long_integer_type_node)
-    return long_long_unsigned_type_node;
-  if (type1 == widest_integer_literal_type_node)
-    return widest_unsigned_literal_type_node;
-#if HOST_BITS_PER_WIDE_INT >= 64
-  if (type1 == intTI_type_node)
-    return unsigned_intTI_type_node;
-#endif
-  if (type1 == intDI_type_node)
-    return unsigned_intDI_type_node;
-  if (type1 == intSI_type_node)
-    return unsigned_intSI_type_node;
-  if (type1 == intHI_type_node)
-    return unsigned_intHI_type_node;
-  if (type1 == intQI_type_node)
-    return unsigned_intQI_type_node;
-
-  return c_common_signed_or_unsigned_type (1, type);
-}
-
 /* Return a signed type the same as TYPE in other respects.  */
 
 tree
@@ -2473,7 +2440,8 @@
 	      default:
 		break;
 	      }
-	  type = c_common_unsigned_type (type);
+	  /* get_unsigned_type doesn't support C bit fields */
+	  type = c_common_signed_or_unsigned_type (1, type);
 	}
 
       if (TREE_CODE (primop0) != INTEGER_CST)
@@ -3640,7 +3608,7 @@
   else
     {
       signed_wchar_type_node = c_common_signed_type (wchar_type_node);
-      unsigned_wchar_type_node = c_common_unsigned_type (wchar_type_node);
+      unsigned_wchar_type_node = get_unsigned_type (wchar_type_node);
     }
 
   /* This is for wide string constants.  */
@@ -3658,7 +3626,7 @@
   default_function_type = build_function_type (integer_type_node, NULL_TREE);
   ptrdiff_type_node
     = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
-  unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
+  unsigned_ptrdiff_type_node = get_unsigned_type (ptrdiff_type_node);
 
   lang_hooks.decls.pushdecl
     (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
=== gcc/c-common.h
==================================================================
--- gcc/c-common.h	(revision 124112)
+++ gcc/c-common.h	(local)
@@ -665,7 +665,6 @@
 extern bool c_common_missing_argument (const char *opt, size_t code);
 extern tree c_common_type_for_mode (enum machine_mode, int);
 extern tree c_common_type_for_size (unsigned int, int);
-extern tree c_common_unsigned_type (tree);
 extern tree c_common_signed_type (tree);
 extern tree c_common_signed_or_unsigned_type (int, tree);
 extern tree c_build_bitfield_integer_type (unsigned HOST_WIDE_INT, int);
=== gcc/c-decl.c
==================================================================
--- gcc/c-decl.c	(revision 124112)
+++ gcc/c-decl.c	(local)
@@ -4086,7 +4086,7 @@
      "signed".  */
   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
       && TREE_CODE (type) == INTEGER_TYPE)
-    type = c_common_unsigned_type (type);
+    type = get_unsigned_type (type);
 
   /* Figure out the type qualifiers for the declaration.  There are
      two ways a declaration can become qualified.  One is something
=== gcc/c-format.c
==================================================================
--- gcc/c-format.c	(revision 124112)
+++ gcc/c-format.c	(local)
@@ -2249,7 +2249,7 @@
 	  && TREE_CODE (cur_type) == INTEGER_TYPE
 	  && (!pedantic || i == 0 || (i == 1 && char_type_flag))
 	  && (TYPE_UNSIGNED (wanted_type)
-	      ? wanted_type == c_common_unsigned_type (cur_type)
+	      ? wanted_type == get_unsigned_type (cur_type)
 	      : wanted_type == c_common_signed_type (cur_type)))
 	continue;
       /* Likewise, "signed char", "unsigned char" and "char" are
=== gcc/c-objc-common.h
==================================================================
--- gcc/c-objc-common.h	(revision 124112)
+++ gcc/c-objc-common.h	(local)
@@ -104,8 +104,6 @@
 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
 #undef LANG_HOOKS_SIGNED_TYPE
 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
-#undef LANG_HOOKS_UNSIGNED_TYPE
-#define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
 #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
=== gcc/c-typeck.c
==================================================================
--- gcc/c-typeck.c	(revision 124112)
+++ gcc/c-typeck.c	(local)
@@ -4080,8 +4080,8 @@
       if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
 	  || (target_cmp = comp_target_types (type, rhstype))
 	  || is_opaque_pointer
-	  || (c_common_unsigned_type (mvl)
-	      == c_common_unsigned_type (mvr)))
+	  || (get_unsigned_type (mvl)
+	      == get_unsigned_type (mvr)))
 	{
 	  if (pedantic
 	      && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
=== gcc/convert.c
==================================================================
--- gcc/convert.c	(revision 124112)
+++ gcc/convert.c	(local)
@@ -656,7 +656,7 @@
 			     || !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1)))
 			    && (ex_form == PLUS_EXPR
 				|| ex_form == MINUS_EXPR)))
-		      typex = lang_hooks.types.unsigned_type (typex);
+		      typex = get_unsigned_type (typex);
 		    else
 		      typex = lang_hooks.types.signed_type (typex);
 		    return convert (type,
@@ -678,7 +678,7 @@
 	    /* Don't do unsigned arithmetic where signed was wanted,
 	       or vice versa.  */
 	    if (TYPE_UNSIGNED (TREE_TYPE (expr)))
-	      typex = lang_hooks.types.unsigned_type (type);
+	      typex = get_unsigned_type (type);
 	    else
 	      typex = lang_hooks.types.signed_type (type);
 	    return convert (type,
=== gcc/cp/cp-objcp-common.h
==================================================================
--- gcc/cp/cp-objcp-common.h	(revision 124112)
+++ gcc/cp/cp-objcp-common.h	(local)
@@ -136,8 +136,6 @@
 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
 #undef LANG_HOOKS_SIGNED_TYPE
 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
-#undef LANG_HOOKS_UNSIGNED_TYPE
-#define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
 #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
=== gcc/cp/decl.c
==================================================================
--- gcc/cp/decl.c	(revision 124112)
+++ gcc/cp/decl.c	(local)
@@ -7371,7 +7371,7 @@
       else if (type == char_type_node)
 	type = unsigned_char_type_node;
       else if (typedef_decl)
-	type = c_common_unsigned_type (type);
+	type = get_unsigned_type (type);
       else
 	type = unsigned_type_node;
     }
=== gcc/expmed.c
==================================================================
--- gcc/expmed.c	(revision 124112)
+++ gcc/expmed.c	(local)
@@ -5044,7 +5044,7 @@
 			  make_tree (type, XEXP (x, 1)));
 
     case LSHIFTRT:
-      t = lang_hooks.types.unsigned_type (type);
+      t = get_unsigned_type (type);
       return fold_convert (type, build2 (RSHIFT_EXPR, t,
 			    		 make_tree (t, XEXP (x, 0)),
 				    	 make_tree (type, XEXP (x, 1))));
@@ -5065,7 +5065,7 @@
 				    	 make_tree (t, XEXP (x, 0)),
 				    	 make_tree (t, XEXP (x, 1))));
     case UDIV:
-      t = lang_hooks.types.unsigned_type (type);
+      t = get_unsigned_type (type);
       return fold_convert (type, build2 (TRUNC_DIV_EXPR, t,
 				    	 make_tree (t, XEXP (x, 0)),
 				    	 make_tree (t, XEXP (x, 1))));
=== gcc/fold-const.c
==================================================================
--- gcc/fold-const.c	(revision 124112)
+++ gcc/fold-const.c	(local)
@@ -1411,7 +1411,7 @@
 	    {
 	      tree ntype = TYPE_UNSIGNED (type)
 			   ? lang_hooks.types.signed_type (type)
-			   : lang_hooks.types.unsigned_type (type);
+			   : get_unsigned_type (type);
 	      tree temp = fold_convert (ntype, TREE_OPERAND (t, 0));
 	      temp = fold_build2 (RSHIFT_EXPR, ntype, temp, op1);
 	      return fold_convert (type, temp);
@@ -4352,7 +4352,7 @@
     {
       if (! TYPE_UNSIGNED (etype))
 	{
-	  etype = lang_hooks.types.unsigned_type (etype);
+	  etype = get_unsigned_type (etype);
 	  high = fold_convert (etype, high);
 	  exp = fold_convert (etype, exp);
 	}
@@ -4420,7 +4420,7 @@
 
       /* Check if (unsigned) INT_MAX + 1 == (unsigned) INT_MIN
 	 for the type in question, as we rely on this here.  */
-      utype = lang_hooks.types.unsigned_type (etype);
+      utype = get_unsigned_type (etype);
       maxv = fold_convert (utype, TYPE_MAX_VALUE (etype));
       maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1,
 			  integer_one_node, 1);
@@ -7805,7 +7805,7 @@
 		  && (LOAD_EXTEND_OP (TYPE_MODE (TREE_TYPE (and0)))
 		      == ZERO_EXTEND))
 		{
-		  tree uns = lang_hooks.types.unsigned_type (TREE_TYPE (and0));
+		  tree uns = get_unsigned_type (TREE_TYPE (and0));
 		  and0 = fold_convert (uns, and0);
 		  and1 = fold_convert (uns, and1);
 		}
@@ -11294,7 +11294,7 @@
 	      || TREE_CODE (arg0) == ROUND_MOD_EXPR)
 	  && integer_pow2p (TREE_OPERAND (arg0, 1)))
 	{
-	  tree newtype = lang_hooks.types.unsigned_type (TREE_TYPE (arg0));
+	  tree newtype = get_unsigned_type (TREE_TYPE (arg0));
 	  tree newmod = fold_build2 (TREE_CODE (arg0), newtype,
 				     fold_convert (newtype,
 						   TREE_OPERAND (arg0, 0)),
@@ -12403,7 +12403,7 @@
 	      else if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == 0
 		       && (TREE_INT_CST_LOW (arg1) & mask_lo) == 0)
 		{
-		  tem_type = lang_hooks.types.unsigned_type (TREE_TYPE (tem));
+		  tem_type = get_unsigned_type (TREE_TYPE (tem));
 		  tem = fold_convert (tem_type, tem);
 		}
 	      else
=== gcc/langhooks-def.h
==================================================================
--- gcc/langhooks-def.h	(revision 124112)
+++ gcc/langhooks-def.h	(local)
@@ -207,13 +207,11 @@
   lhd_omp_firstprivatize_type_sizes
 #define LANG_HOOKS_HASH_TYPES		true
 
-#define LANG_HOOKS_UNSIGNED_TYPE get_unsigned_type
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
   LANG_HOOKS_TYPE_FOR_MODE, \
   LANG_HOOKS_TYPE_FOR_SIZE, \
-  LANG_HOOKS_UNSIGNED_TYPE, \
   LANG_HOOKS_SIGNED_TYPE, \
   LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE, \
   LANG_HOOKS_GENERIC_TYPE_P, \
=== gcc/langhooks.h
==================================================================
--- gcc/langhooks.h	(revision 124112)
+++ gcc/langhooks.h	(local)
@@ -103,10 +103,6 @@
      integer type with at least that precision.  */
   tree (*type_for_size) (unsigned, int);
 
-  /* Given an integer type T, return a type like T but unsigned.
-     If T is unsigned, the value is T.  */
-  tree (*unsigned_type) (tree);
-
   /* Given an integer type T, return a type like T but signed.
      If T is signed, the value is T.  */
   tree (*signed_type) (tree);
=== gcc/tree.c
==================================================================
--- gcc/tree.c	(revision 124112)
+++ gcc/tree.c	(local)
@@ -7676,8 +7676,8 @@
 unsigned_type_for (tree type)
 {
   if (POINTER_TYPE_P (type))
-    return lang_hooks.types.unsigned_type (size_type_node);
-  return lang_hooks.types.unsigned_type (type);
+    return get_unsigned_type (size_type_node);
+  return get_unsigned_type (type);
 }
 
 /* Returns signed variant of TYPE.  */

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