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] Eliminate signed sizetypes (3/3)


This finally eliminates signed sizetypes, in the sense that front-ends must 
now pass an unsigned type to set_sizetype.  The middle-end then derives a 
proper signed variant of this unsigned sizetype.  This also fixes incorrect 
uses of size_type_node in lieu of sizetype (and one the other way around).

Tested on x86_64-suse-linux, OK for the mainline?


2010-04-18  Eric Botcazou  <ebotcazou@adacore.com>

	* fold-const.c (fold_comparison): Use ssizetype.
	* gimple-fold.c (maybe_fold_offset_to_array_ref): Likewise.
	* ipa-prop.c (ipa_modify_call_arguments): Use sizetype.
	* tree-loop-distribution.c (build_size_arg_loc): Likewise.
	* tree-object-size.c (compute_object_sizes): Use size_type_node.

	* tree.h (initialize_sizetypes): Remove parameter.
	(build_common_tree_nodes): Remove second parameter.
	* stor-layout.c (initialize_sizetypes): Remove parameter.
	Always create an unsigned type.
	(set_sizetype): Assert that the passed type is unsigned and simplify.
	* tree.c (build_common_tree_nodes): Remove second parameter.
	Adjust call to initialize_sizetypes.
	* c-decl.c (c_init_decl_processing): Remove second argument in call to
	build_common_tree_nodes.
cp/
	* decl.c (cxx_init_decl_processing): Remove second argument in call to
	build_common_tree_nodes.

java/
	* decl.c (java_init_decl_processing): Remove argument in call to
	initialize_sizetypes

fortran/
	* f95-lang.c (gfc_init_decl_processing): Remove second argument in call
	to build_common_tree_nodes.

ada/
	* gcc-interface/misc.c (gnat_init): Remove second argument in call to
	build_common_tree_nodes.

lto/
	* lto-lang.c (lto_init): Remove second argument in call to
	build_common_tree_nodes.


-- 
Eric Botcazou
Index: tree-loop-distribution.c
===================================================================
--- tree-loop-distribution.c	(revision 158469)
+++ tree-loop-distribution.c	(working copy)
@@ -227,12 +227,8 @@ build_size_arg_loc (location_t loc, tree
 		    gimple_seq *stmt_list)
 {
   gimple_seq stmts;
-  tree x;
-
-  x = fold_build2_loc (loc, MULT_EXPR, size_type_node,
-		       fold_convert_loc (loc, size_type_node, nb_iter),
-		       fold_convert_loc (loc, size_type_node,
-					 TYPE_SIZE_UNIT (TREE_TYPE (op))));
+  tree x = size_binop (MULT_EXPR, fold_convert_loc (loc, sizetype, nb_iter),
+		       TYPE_SIZE_UNIT (TREE_TYPE (op)));
   x = force_gimple_operand (x, &stmts, true, NULL);
   gimple_seq_add_seq (stmt_list, stmts);
 
Index: java/decl.c
===================================================================
--- java/decl.c	(revision 158469)
+++ java/decl.c	(working copy)
@@ -579,7 +579,7 @@ java_init_decl_processing (void)
   TREE_TYPE (error_mark_node) = error_mark_node;
 
   /* Create sizetype first - needed for other types. */
-  initialize_sizetypes (false);
+  initialize_sizetypes ();
 
   byte_type_node = make_signed_type (8);
   pushdecl (build_decl (BUILTINS_LOCATION,
Index: tree.c
===================================================================
--- tree.c	(revision 158469)
+++ tree.c	(working copy)
@@ -8747,12 +8747,12 @@ make_or_reuse_accum_type (unsigned size,
    this function to select one of the types as sizetype.  */
 
 void
-build_common_tree_nodes (bool signed_char, bool signed_sizetype)
+build_common_tree_nodes (bool signed_char)
 {
   error_mark_node = make_node (ERROR_MARK);
   TREE_TYPE (error_mark_node) = error_mark_node;
 
-  initialize_sizetypes (signed_sizetype);
+  initialize_sizetypes ();
 
   /* Define both `signed char' and `unsigned char'.  */
   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
Index: tree.h
===================================================================
--- tree.h	(revision 158469)
+++ tree.h	(working copy)
@@ -3967,7 +3967,7 @@ extern tree make_unsigned_type (int);
 extern tree signed_or_unsigned_type_for (int, tree);
 extern tree signed_type_for (tree);
 extern tree unsigned_type_for (tree);
-extern void initialize_sizetypes (bool);
+extern void initialize_sizetypes (void);
 extern void set_sizetype (tree);
 extern void fixup_unsigned_type (tree);
 extern tree build_pointer_type_for_mode (tree, enum machine_mode, bool);
@@ -4981,7 +4981,7 @@ extern int real_onep (const_tree);
 extern int real_twop (const_tree);
 extern int real_minus_onep (const_tree);
 extern void init_ttree (void);
-extern void build_common_tree_nodes (bool, bool);
+extern void build_common_tree_nodes (bool);
 extern void build_common_tree_nodes_2 (int);
 extern void build_common_builtin_nodes (void);
 extern tree build_nonstandard_integer_type (unsigned HOST_WIDE_INT, int);
Index: fold-const.c
===================================================================
--- fold-const.c	(revision 158469)
+++ fold-const.c	(working copy)
@@ -8695,24 +8695,19 @@ fold_comparison (location_t loc, enum tr
 		   && ((code == EQ_EXPR || code == NE_EXPR)
 		       || POINTER_TYPE_OVERFLOW_UNDEFINED))
 	    {
-	      tree signed_size_type_node;
-	      signed_size_type_node = signed_type_for (size_type_node);
-
 	      /* By converting to signed size type we cover middle-end pointer
 	         arithmetic which operates on unsigned pointer types of size
 	         type size and ARRAY_REF offsets which are properly sign or
 	         zero extended from their type in case it is narrower than
 	         size type.  */
 	      if (offset0 == NULL_TREE)
-		offset0 = build_int_cst (signed_size_type_node, 0);
+		offset0 = build_int_cst (ssizetype, 0);
 	      else
-		offset0 = fold_convert_loc (loc, signed_size_type_node,
-					    offset0);
+		offset0 = fold_convert_loc (loc, ssizetype, offset0);
 	      if (offset1 == NULL_TREE)
-		offset1 = build_int_cst (signed_size_type_node, 0);
+		offset1 = build_int_cst (ssizetype, 0);
 	      else
-		offset1 = fold_convert_loc (loc, signed_size_type_node,
-					    offset1);
+		offset1 = fold_convert_loc (loc, ssizetype, offset1);
 
 	      if (code != EQ_EXPR
 		  && code != NE_EXPR
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 158469)
+++ cp/decl.c	(working copy)
@@ -3358,7 +3358,7 @@ cxx_init_decl_processing (void)
   tree void_ftype;
   tree void_ftype_ptr;
 
-  build_common_tree_nodes (flag_signed_char, false);
+  build_common_tree_nodes (flag_signed_char);
 
   /* Create all the identifiers we need.  */
   initialize_predefined_identifiers ();
Index: ada/gcc-interface/misc.c
===================================================================
--- ada/gcc-interface/misc.c	(revision 158469)
+++ ada/gcc-interface/misc.c	(working copy)
@@ -391,7 +391,7 @@ gnat_init (void)
   /* Do little here, most of the standard declarations are set up after the
      front-end has been run.  Use the same `char' as C, this doesn't really
      matter since we'll use the explicit `unsigned char' for Character.  */
-  build_common_tree_nodes (flag_signed_char, false);
+  build_common_tree_nodes (flag_signed_char);
 
   /* In Ada, we use the unsigned type corresponding to the width of Pmode as
      SIZETYPE.  In most cases when ptr_mode and Pmode differ, C will use the
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 158469)
+++ c-decl.c	(working copy)
@@ -3454,7 +3454,7 @@ c_init_decl_processing (void)
      using preprocessed headers.  */
   input_location = BUILTINS_LOCATION;
 
-  build_common_tree_nodes (flag_signed_char, false);
+  build_common_tree_nodes (flag_signed_char);
 
   c_common_nodes_and_builtins ();
 
Index: fortran/f95-lang.c
===================================================================
--- fortran/f95-lang.c	(revision 158469)
+++ fortran/f95-lang.c	(working copy)
@@ -542,7 +542,7 @@ gfc_init_decl_processing (void)
   /* Build common tree nodes. char_type_node is unsigned because we
      only use it for actual characters, not for INTEGER(1). Also, we
      want double_type_node to actually have double precision.  */
-  build_common_tree_nodes (false, false);
+  build_common_tree_nodes (false);
   /* x86_64 mingw32 has a sizetype of "unsigned long long", most other hosts
      have a sizetype of "unsigned long". Therefore choose the correct size
      in mostly target independent way.  */
Index: stor-layout.c
===================================================================
--- stor-layout.c	(revision 158469)
+++ stor-layout.c	(working copy)
@@ -2214,37 +2214,35 @@ make_accum_type (int precision, int unsi
    value to enable integer types to be created.  */
 
 void
-initialize_sizetypes (bool signed_p)
+initialize_sizetypes (void)
 {
   tree t = make_node (INTEGER_TYPE);
   int precision = GET_MODE_BITSIZE (SImode);
 
   SET_TYPE_MODE (t, SImode);
   TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
-  TYPE_USER_ALIGN (t) = 0;
   TYPE_IS_SIZETYPE (t) = 1;
-  TYPE_UNSIGNED (t) = !signed_p;
+  TYPE_UNSIGNED (t) = 1;
   TYPE_SIZE (t) = build_int_cst (t, precision);
   TYPE_SIZE_UNIT (t) = build_int_cst (t, GET_MODE_SIZE (SImode));
   TYPE_PRECISION (t) = precision;
 
-  /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE.  */
-  set_min_and_max_values_for_integral_type (t, precision, !signed_p);
+  set_min_and_max_values_for_integral_type (t, precision, true);
 
   sizetype = t;
   bitsizetype = build_distinct_type_copy (t);
 }
 
-/* Make sizetype a version of TYPE, and initialize *sizetype
-   accordingly.  We do this by overwriting the stub sizetype and
-   bitsizetype nodes created by initialize_sizetypes.  This makes sure
-   that (a) anything stubby about them no longer exists, (b) any
-   INTEGER_CSTs created with such a type, remain valid.  */
+/* Make sizetype a version of TYPE, and initialize *sizetype accordingly.
+   We do this by overwriting the stub sizetype and bitsizetype nodes created
+   by initialize_sizetypes.  This makes sure that (a) anything stubby about
+   them no longer exists and (b) any INTEGER_CSTs created with such a type,
+   remain valid.  */
 
 void
 set_sizetype (tree type)
 {
-  tree t;
+  tree t, max;
   int oprecision = TYPE_PRECISION (type);
   /* The *bitsizetype types use a precision that avoids overflows when
      calculating signed sizes / offsets in bits.  However, when
@@ -2257,11 +2255,11 @@ set_sizetype (tree type)
   if (precision > HOST_BITS_PER_WIDE_INT * 2)
     precision = HOST_BITS_PER_WIDE_INT * 2;
 
-  gcc_assert (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (sizetype));
+  /* sizetype must be an unsigned type.  */
+  gcc_assert (TYPE_UNSIGNED (type));
 
   t = build_distinct_type_copy (type);
-  /* We do want to use sizetype's cache, as we will be replacing that
-     type.  */
+  /* We want to use sizetype's cache, as we will be replacing that type.  */
   TYPE_CACHED_VALUES (t) = TYPE_CACHED_VALUES (sizetype);
   TYPE_CACHED_VALUES_P (t) = TYPE_CACHED_VALUES_P (sizetype);
   TREE_TYPE (TYPE_CACHED_VALUES (t)) = type;
@@ -2273,10 +2271,17 @@ set_sizetype (tree type)
   TYPE_MAIN_VARIANT (sizetype) = sizetype;
   TYPE_CANONICAL (sizetype) = sizetype;
 
+  /* sizetype is unsigned but we need to fix TYPE_MAX_VALUE so that it is
+     sign-extended in a way consistent with force_fit_type.  */
+  max = TYPE_MAX_VALUE (sizetype);
+  TYPE_MAX_VALUE (sizetype)
+    = build_int_cst_wide_type (sizetype,
+			       TREE_INT_CST_LOW (max),
+			       TREE_INT_CST_HIGH (max));
+
   t = make_node (INTEGER_TYPE);
   TYPE_NAME (t) = get_identifier ("bit_size_type");
-  /* We do want to use bitsizetype's cache, as we will be replacing that
-     type.  */
+  /* We want to use bitsizetype's cache, as we will be replacing that type.  */
   TYPE_CACHED_VALUES (t) = TYPE_CACHED_VALUES (bitsizetype);
   TYPE_CACHED_VALUES_P (t) = TYPE_CACHED_VALUES_P (bitsizetype);
   TYPE_PRECISION (t) = precision;
@@ -2288,36 +2293,13 @@ set_sizetype (tree type)
   TYPE_MAIN_VARIANT (bitsizetype) = bitsizetype;
   TYPE_CANONICAL (bitsizetype) = bitsizetype;
 
-  if (TYPE_UNSIGNED (type))
-    {
-      fixup_unsigned_type (bitsizetype);
-      ssizetype = make_signed_type (oprecision);
-      TYPE_IS_SIZETYPE (ssizetype) = 1;
-      sbitsizetype = make_signed_type (precision);
-      TYPE_IS_SIZETYPE (sbitsizetype) = 1;
-    }
-  else
-    {
-      fixup_signed_type (bitsizetype);
-      ssizetype = sizetype;
-      sbitsizetype = bitsizetype;
-    }
-
-  /* If SIZETYPE is unsigned, we need to fix TYPE_MAX_VALUE so that
-     it is sign extended in a way consistent with force_fit_type.  */
-  if (TYPE_UNSIGNED (type))
-    {
-      tree orig_max, new_max;
-
-      orig_max = TYPE_MAX_VALUE (sizetype);
-
-      /* Build a new node with the same values, but a different type.
-	 Sign extend it to ensure consistency.  */
-      new_max = build_int_cst_wide_type (sizetype,
-					 TREE_INT_CST_LOW (orig_max),
-					 TREE_INT_CST_HIGH (orig_max));
-      TYPE_MAX_VALUE (sizetype) = new_max;
-    }
+  fixup_unsigned_type (bitsizetype);
+
+  /* Create the signed variants of *sizetype.  */
+  ssizetype = make_signed_type (oprecision);
+  TYPE_IS_SIZETYPE (ssizetype) = 1;
+  sbitsizetype = make_signed_type (precision);
+  TYPE_IS_SIZETYPE (sbitsizetype) = 1;
 }
 
 /* TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE
Index: gimple-fold.c
===================================================================
--- gimple-fold.c	(revision 158469)
+++ gimple-fold.c	(working copy)
@@ -159,7 +159,7 @@ maybe_fold_offset_to_array_ref (location
     return NULL_TREE;
 
   /* Use signed size type for intermediate computation on the index.  */
-  idx_type = signed_type_for (size_type_node);
+  idx_type = ssizetype;
 
   /* If OFFSET and ELT_OFFSET are zero, we don't care about the size of the
      element type (so we can use the alignment if it's not constant).
Index: lto/lto-lang.c
===================================================================
--- lto/lto-lang.c	(revision 158469)
+++ lto/lto-lang.c	(working copy)
@@ -1039,7 +1039,7 @@ lto_init (void)
   linemap_add (line_table, LC_RENAME, 0, NULL, 0);
 
   /* Create the basic integer types.  */
-  build_common_tree_nodes (flag_signed_char, /*signed_sizetype=*/false);
+  build_common_tree_nodes (flag_signed_char);
 
   /* Share char_type_node with whatever would be the default for the target.
      char_type_node will be used for internal types such as
Index: ipa-prop.c
===================================================================
--- ipa-prop.c	(revision 158469)
+++ ipa-prop.c	(working copy)
@@ -1700,7 +1700,7 @@ ipa_modify_call_arguments (struct cgraph
 	      if (!useless_type_conversion_p (ptrtype, TREE_TYPE (expr)))
 		expr = fold_convert (ptrtype, expr);
 	      expr = fold_build2 (POINTER_PLUS_EXPR, ptrtype, expr,
-				  build_int_cst (size_type_node,
+				  build_int_cst (sizetype,
 						 adj->offset / BITS_PER_UNIT));
 	      if (!adj->by_ref)
 		expr = fold_build1 (INDIRECT_REF, adj->type, expr);
Index: tree-object-size.c
===================================================================
--- tree-object-size.c	(revision 158469)
+++ tree-object-size.c	(working copy)
@@ -1203,7 +1203,8 @@ compute_object_sizes (void)
 			result = fold_convert (size_type_node,
 					       integer_minus_one_node);
 		      else if (object_size_type < 4)
-			result = size_zero_node;
+			result = fold_convert (size_type_node,
+					       integer_zero_node);
 		    }
 		}
 

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