This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [varasm] patch for integer_cst non-int-sized pointer initializers
- From: DJ Delorie <dj at redhat dot com>
- To: roger at eyesopen dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 20 Jan 2006 16:55:46 -0500
- Subject: Re: [varasm] patch for integer_cst non-int-sized pointer initializers
- References: <Pine.LNX.4.44.0601192231470.3456-100000@www.eyesopen.com>
> It must have been a bad day at the office as you also didn't mention
> whether and where you'd bootstraped it, but the recent ping confirmed
> that this has been tested on some x86_64 triple.
>
> Ok for mainline with the obvious corrections above.
I re-bootstrap-regression-tested it just in case, with the corrections
you suggested. Patch as committed:
2006-01-20 DJ Delorie <dj@redhat.com>
* varasm.c (initialize_constant_valid_p): Allow pointers
initialized from integer constants of lesser precision.
(output_constant): Allow non-int-sized pointer modes to be
initialized from integer constants.
Index: varasm.c
===================================================================
--- varasm.c (revision 110040)
+++ varasm.c (working copy)
@@ -3553,6 +3553,9 @@ initializer_constant_valid_p (tree value
|| TREE_CODE (dest_type) == OFFSET_TYPE)
&& INTEGRAL_TYPE_P (src_type))
{
+ if (TREE_CODE (src) == INTEGER_CST
+ && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
+ return null_pointer_node;
if (integer_zerop (src))
return null_pointer_node;
else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
@@ -3732,6 +3735,11 @@ output_constant (tree exp, unsigned HOST
way. */
if (TREE_CODE (exp) == ADDR_EXPR)
exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
+ /* Likewise for constant ints. */
+ else if (TREE_CODE (exp) == INTEGER_CST)
+ exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
+ TREE_INT_CST_HIGH (exp));
+
}
/* Eliminate any conversions since we'll be outputting the underlying