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]

Re: [PATCH] Fix 32/64 bit pointer size problem in convert


On Fri, Jul 24, 2009 at 09:03:37AM -0700, Douglas B Rupp wrote:
> VMS uses both 32bit and 64bit pointers, this fixes a bug in 
> convert_to_pointer.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu
> 
> OK to commit?
> 
> --Douglas Rupp for Olivier Hainque
> AdaCore

> 2009-07-24  Olivier Hainque  <hainque@adacore.com>
>             Douglas B Rupp  <rupp@gnat.com>
> 
> 	* convert.c (convert_to_pointer): Don't assume the target
> 	pointer type is POINTER_SIZE long. Fetch its precision instead.
> 
> --- gcc/convert.c.old	Thu Jul 16 23:44:01 2009
> +++ gcc/convert.c	Thu Jul 16 23:46:26 2009
> @@ -59,12 +59,21 @@
>      case INTEGER_TYPE:
>      case ENUMERAL_TYPE:
>      case BOOLEAN_TYPE:
> -      if (TYPE_PRECISION (TREE_TYPE (expr)) != POINTER_SIZE)
> -	expr = fold_build1_loc (loc, NOP_EXPR,
> -                            lang_hooks.types.type_for_size (POINTER_SIZE, 0),
> -			    expr);
> -      return fold_build1_loc (loc, CONVERT_EXPR, type, expr);
> +      {
> +	/* If the input precision differs from the target pointer type
> +	   precision, first convert the input expression to an integer type of
> +	   the target precision.  Some targets, e.g. VMS, need several pointer
> +	   sizes to coexist so the latter isn't necessarily POINTER_SIZE.  */
> +	unsigned int pprec = TYPE_PRECISION (type);
> +	unsigned int eprec = TYPE_PRECISION (TREE_TYPE (expr));
> +
> + 	if (eprec != pprec)
> +	  expr = fold_build1_loc (loc, NOP_EXPR,
> +			      lang_hooks.types.type_for_size (pprec, 0),
> +			      expr);
> +      }
> 
> +      return fold_build1_loc (loc, CONVERT_EXPR, type, expr);
> 
>      default:
>        error ("cannot convert to a pointer type");

This is one of several places that Ben, Ulrich, and I had to put in code for
the named addresss branch which introduces the concept of different named
address spaces, where you can have different sized pointers.

Calculation of the type that you get from pointer subtraction is another area
where having different pointer sizes can bite you.

IMHO, having a single global POINTER_SIZE and Pmode is one of those unfortunate
design choices that comes from thinking all of the world is a VAX (m68k, x86,
etc.).

-- 
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@linux.vnet.ibm.com


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