[PATCH] Handle '\0' in strcmp in RTL expansion (PR tree-optimization/90892).

Martin Liška mliska@suse.cz
Tue Jun 18 08:07:00 GMT 2019


On 6/17/19 11:35 AM, Jakub Jelinek wrote:
> On Mon, Jun 17, 2019 at 11:26:03AM +0200, Martin Liška wrote:
>> diff --git a/gcc/builtins.c b/gcc/builtins.c
>> index 3463ffb1539..917852071b9 100644
>> --- a/gcc/builtins.c
>> +++ b/gcc/builtins.c
>> @@ -7142,6 +7142,20 @@ inline_expand_builtin_string_cmp (tree exp, rtx target)
>>    const char *src_str1 = c_getstr (arg1, &len1);
>>    const char *src_str2 = c_getstr (arg2, &len2);
>>  
>> +  if (src_str1 != NULL)
>> +    {
>> +      unsigned HOST_WIDE_INT str_str1_strlen = strlen (src_str1);
>> +      if (str_str1_strlen + 1 < len1)
>> +	len1 = str_str1_strlen + 1;
> 
> So use strnlen instead of strlen?
>   if (src_str1 != NULL)
>     len1 = strnlen (src_str1, len1);
> etc.?

Sure, done in attached patch.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

> 
> 	Jakub
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Handle-0-in-strcmp-in-RTL-expansion-PR-tree-optimiza.patch
Type: text/x-patch
Size: 1956 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190618/4a400784/attachment.bin>


More information about the Gcc-patches mailing list