Patchwork cp/cvt: don't assume pointer sizes

login
register
mail settings
Submitter DJ Delorie
Date July 21, 2011, 9:50 p.m.
Message ID <201107212150.p6LLolwN031611@greed.delorie.com>
Download mbox | patch
Permalink /patch/106176/
State New
Headers show

Comments

DJ Delorie - July 21, 2011, 9:50 p.m.
Some targets (m32c, tpf, mips) have more than one pointer size.  It is
not correct to assume that a pointer is POINTER_SIZE.


TPF tescase (default pointer and int are 64 bits):

typedef void * __attribute__ ((mode (SI))) __ptr32_t;

unsigned int foo;
__ptr32_t foo_addr;

int bar( )
{
  foo_addr = (__ptr32_t)foo;
  return 0;
}

Patch

Index: gcc/cp/cvt.c
===================================================================
--- gcc/cp/cvt.c	(revision 176554)
+++ gcc/cp/cvt.c	(working copy)
@@ -217,15 +217,16 @@  cp_convert_to_pointer (tree type, tree e
       error ("invalid conversion from %qT to %qT", intype, type);
       return error_mark_node;
     }
 
   if (INTEGRAL_CODE_P (form))
     {
-      if (TYPE_PRECISION (intype) == POINTER_SIZE)
+      int this_pointer_size = TYPE_PRECISION (type);
+      if (TYPE_PRECISION (intype) == this_pointer_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 (this_pointer_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.  */
       gcc_assert (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr)))
 		  == GET_MODE_SIZE (TYPE_MODE (type)));