Please review writeup for fixing PR 78809 (inline strcmp for small constant strings)
Jeff Law
law@redhat.com
Sat Nov 18 01:39:00 GMT 2017
On 11/17/2017 03:20 PM, Qing Zhao wrote:
>
>> On Nov 16, 2017, at 6:24 PM, Martin Sebor <msebor@gmail.com
>> <mailto:msebor@gmail.com>> wrote:
>>>
>>> In my current local implementation, I used the following routine to
>>> get the range info: Â (and use the MINMAXLEN[1]+1 for the length of
>>> the non-constant string)
>>>
>>> /* Determine the minimum and maximum value or string length that ARG
>>> Â Â refers to and store each in the first two elements of MINMAXLEN.
>>> Â Â For expressions that point to strings of unknown lengths that are
>>> Â Â character arrays, use the upper bound of the array as the maximum
>>> Â Â length. Â For example, given an expression like 'x ? array : "xyz"'
>>> Â Â and array declared as 'char array[8]', MINMAXLEN[0] will be set
>>> Â Â to 3 and MINMAXLEN[1] to 7, the longest string that could be
>>> Â Â stored in array.
>>> Â Â Return true if the range of the string lengths has been obtained
>>> Â Â from the upper bound of an array at the end of a struct. Â Such
>>> Â Â an array may hold a string that's longer than its upper bound
>>> Â Â due to it being used as a poor-man's flexible array member. Â */
>>>
>>> bool
>>> get_range_strlen (tree arg, tree minmaxlen[2])
>>> {
>>> }
>>>
>>> However, this routine currently miss a very obvious case as the
>>> following:
>>>
>>> char s[100] = {'a','b','c','dâ};
>>>
>>> __builtin_strcmp(s, "abc") != 0
>>>
>>> So, I have to change this routine to include such common case.
>>
>> There was a discussion some time ago about converting CONSTRUCTOR
>> trees emitted for array initializers like the above to STRING_CST
>> (see bug 71625 for some background). Â I think that would still be
>> the ideal solution. Â Then you wouldn't have to change
>> get_range_strlen.
>
> thanks for the info, Martin.
>
> In my case, itâs the size of â100â cannot be collected in the
> MINMAXLEN[1] for the string âsâ.Â
>
> I need to make sure that the size of variable string s is larger than
> the size of constant string âabcâ to guarantee the safety of the
> transformation.
>
> currently, âget_range_strlenâ cannot identify the simple VAR_DECL with
> array_type to determine the maximum size of the string.
It sounds more like you want the object_size interfaces. See
tree-object-size.[ch]
Jeff
More information about the Gcc
mailing list