This is the mail archive of the 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] initiailzing non-default-sized pointers

In line with my query about non-default-sized pointers, I'd like
to at least get this much in.  This allows you to initialize such pointers
with integer constants, such as this:

	typedef void (*ifunc)() __attribute__((mode(SI)));
	extern ifunc ivects[];

	  ivects[4] = (ifunc) 789888L;

Without this patch, the value gets truncated to 16 bits (assuming
HImode pointers, like m16c).  Tested with m16c (Pmode==HImode) and
m32c (Pmode==SImode).

	* fold-const.c (force_fit_type): Don't assume pointers are
	always the same size.
	* convert.c (convert_to_pointer): Convert to requested size,
	not the default size.

	* cvt.c (cp_convert_to_pointer): Convert to requested size,
	not the default size.

Index: fold-const.c
--- fold-const.c	(revision 116166)
+++ fold-const.c	(working copy)
@@ -217,8 +217,7 @@ force_fit_type (tree t, int overflowable
   low = TREE_INT_CST_LOW (t);
   high = TREE_INT_CST_HIGH (t);
     prec = POINTER_SIZE;
     prec = TYPE_PRECISION (TREE_TYPE (t));
Index: convert.c
--- convert.c	(revision 116166)
+++ convert.c	(working copy)
@@ -41,6 +41,8 @@ Software Foundation, 51 Franklin Street,
 convert_to_pointer (tree type, tree expr)
+  int type_ptr_size = TYPE_PRECISION (type);
   if (TREE_TYPE (expr) == type)
     return expr;
@@ -62,9 +64,9 @@ convert_to_pointer (tree type, tree expr
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
+      if (TYPE_PRECISION (TREE_TYPE (expr)) != type_ptr_size)
 	expr = fold_build1 (NOP_EXPR,
-                            lang_hooks.types.type_for_size (POINTER_SIZE, 0),
+                            lang_hooks.types.type_for_size (type_ptr_size, 0),
       return fold_build1 (CONVERT_EXPR, type, expr);
Index: cp/cvt.c
--- cp/cvt.c	(revision 116166)
+++ cp/cvt.c	(working copy)
@@ -268,9 +268,11 @@ cp_convert_to_pointer (tree type, tree e
   if (INTEGRAL_CODE_P (form))
-      if (TYPE_PRECISION (intype) == POINTER_SIZE)
+      int type_ptr_size = TYPE_PRECISION (type);
+      if (TYPE_PRECISION (intype) == type_ptr_size)
 	return build1 (CONVERT_EXPR, type, expr);
-      expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr);
+      expr = cp_convert (c_common_type_for_size (type_ptr_size, 0), expr);
       /* Modes may be different but sizes should be the same.  There
 	 is supposed to be some integral type that is the same width
 	 as a pointer.  */

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