On Tue, Mar 25, 2025 at 01:01:59PM -0400, James K. Lowden wrote:
> (I'm sure that's true.  In my defense, the nonterminal is named
> "count", and the comment is 
> 
>       // verify not floating point with nonzero fraction
> 
> but I admit that's not a lot to go on.)
> 
> Let me clarify.  :-) 
> 
> What we're dealing with here is an array subscript.   When the constant
> compile-time expression is parsed, we don't know how it will be used;
> we find out only when it's used as a subscript.  As an array subscript,
> it can't be negative, fractional, or larger than the target's address
> space.   
> 
> In fact, we shouldn't use floating point for numeric literals. We
> grabbed _Float128 because it was available and served our purpose. Per
> the ISO specification, though, numeric literals are not floating point.
> They are fixed-point.  
> 
> Given considerations like -0.0 and infinities and NaNs, perhaps we're
> better off switching to FIXED_POINT_TYPE, where they don't apply.  
> 
> If we just check for a positive integral value not too big, that should
> suffice for now.  Once we switch to fixed point, it will be correct.  
> 
> How does that sound?  

So, if it is an array subscript, it needs to be something that fits
into the target size_t, so TYPE_PRECISION (size_type_node) is the right
precision for use there.

Plus the question is if one can actually see infinities or NaNs in the value
or if something ensures those don't appear.
E.g. if one specifies a really large constant whether it isn't turned into
infinity (and then would cause UB on the size_t(...) cast).

        Jakub

Reply via email to