This is the mail archive of the
mailing list for the GCC project.
Re: PATCH RFC: Narrowing POINTER_PLUS_EXPR can be a static initializer
Ian Lance Taylor <firstname.lastname@example.org> writes:
> Eric Botcazou <email@example.com> writes:
>> AFAICS the "narrowing" is not conveyed by "endtype" but rather by the operands
>> of the operation (there is no return NULL_TREE at the end of the conditional
>> blocks). And, in the new code, "endtype" can be anything.
> You're right, an exact translation would check for INTEGRAL_TYPE_P
> (endtype) in the MINUS_EXPR case. As far as I can see it doesn't
> actually matter, because the only case which is handled differently is
> a subtraction of two labels, and it seems to me that that is a
> constant regardless. But, yes, the name and the comment are wrong.
> I'll look into fixing it.
Fixed like this on trunk. Bootstrapped and checked on
i686-pc-linux-gnu. No fix needed on 4.3 branch, as there it already
works this way.
Eric, thanks for pointing out this buglet.
2008-09-19 Ian Lance Taylor <firstname.lastname@example.org>
* varasm.c (narrowing_initializer_constant_valid_p): Return
NULL_TREE if ENDTYPE is not an integer.
--- varasm.c (revision 140501)
+++ varasm.c (working copy)
@@ -4064,9 +4064,10 @@
/* A subroutine of initializer_constant_valid_p. VALUE is either a
- MINUS_EXPR or a POINTER_PLUS_EXPR, and ENDTYPE is a narrowing
- conversion to something smaller than a pointer. This returns
- null_pointer_node if the resulting value is an absolute constant
+ MINUS_EXPR or a POINTER_PLUS_EXPR. This looks for cases of VALUE
+ which are valid when ENDTYPE is an integer of any size; in
+ particular, this does not accept a pointer minus a constant. This
+ returns null_pointer_node if the VALUE is an absolute constant
which can be used to initialize a static variable. Otherwise it
returns NULL. */
@@ -4075,6 +4076,9 @@
tree op0, op1;
+ if (!INTEGRAL_TYPE_P (endtype))
+ return NULL_TREE;
op0 = TREE_OPERAND (value, 0);
op1 = TREE_OPERAND (value, 1);