get_range_query vs NULL argument

Aldy Hernandez aldyh@redhat.com
Thu Feb 16 08:10:36 GMT 2023



On 2/16/23 08:57, Richard Biener wrote:
> On Wed, Feb 15, 2023 at 11:31 PM Andrew MacLeod via Gcc <gcc@gcc.gnu.org> wrote:
>>
>>
>> On 2/15/23 14:50, Andrew Pinski wrote:
>>> Hi,
>>>     While fixing PR 108354, I came across that
>>> ssa_name_has_boolean_range calls get_range_query with cfun as the
>>> argument but sometimes while in IPA passes cfun is currently nullptr.
>>> The question should we check the argument before calling
>>> get_range_query or is it a valid thing to call it with a nullptr (and
>>> have it return global_ranges in that case)?
>>
>> That might be ok...  personally I see nothing wrong with:
>>
>> diff --git a/gcc/value-query.h b/gcc/value-query.h
>> index 63878968118..2d7bf8fcf33 100644
>> --- a/gcc/value-query.h
>> +++ b/gcc/value-query.h
>> @@ -140,7 +140,7 @@ get_global_range_query ()
>>    ATTRIBUTE_RETURNS_NONNULL inline range_query *
>>    get_range_query (const struct function *fun)
>>    {
>> -  return fun->x_range_query ? fun->x_range_query : &global_ranges;
>> +  return (fun && fun->x_range_query) ? fun->x_range_query : &global_ranges;
>>    }
>>
>>    // Query the global range of NAME in function F.  Default to cfun.
>>
>>
>> The client is probably going to do that anyway.
> 
> But if there's no 'fun', what is 'global_ranges' initialized for?  Or
> is 'global_ranges'
> usable in IPA context?

If there is no fun, global_ranges will just return what get_range_info() 
used to return (i.e. SSA_NAME_RANGE_INFO).

Aldy



More information about the Gcc mailing list