On 6/7/19 1:12 PM, Martin Sebor wrote:
> On 6/6/19 3:53 PM, Jeff Law wrote:
>> On 6/5/19 4:51 PM, Martin Sebor wrote:
>>> One of my new tests for the strlen/sprintf integration tripped
>>> over an incomplete handling of VLAs by the strlen pass.  Where
>>> it can determine the length of a substring at some offset with
>>> other kinds of arrays, the pass fails with VLAs because they
>>> are represented as pointers to arrays.
>>>
>>> The attached patch adds the missing handling so that code like
>>> the following can be fully folded even for VLAs.
>>>
>>>    int f (int n)
>>>    {
>>>      char a[n];
>>>      strcpy (a, "12345");
>>>      if (strlen (&a[2]) != 3)
>>>        abort ();
>>>    }
>>>
>>> Tested on x86_64-linux.
>>>
>>> Martin
>>>
>>> gcc-90662.diff
>>>
>>> PR tree-optimization/90662 - strlen of a string in a vla plus offset not 
>>> folded
>>>
>>>
>>> gcc/ChangeLog:
>>>
>>>     PR tree-optimization/90662
>>>     * tree-ssa-strlen.c (get_stridx): Handle simple VLAs and pointers
>>>     to arrays.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>>     PR tree-optimization/90662
>>>     * gcc.dg/strlenopt-62.c: New test.
>>>     * gcc.dg/strlenopt-63.c: New test.
>> We're relying on the fact that in a MEM_REF the offset is always a byte
>> offset, so no scaling for wchars needed, right?
> 
> I was assuming that the strlen pass only deals with narrow chars.
> But it can be called on a wide character array (or an array of
> any other type) even if it makes little sense, and the code isn't
> prepared to handle that.  Thanks for the hint!  The attached
> revision adds the scaling along with tests for non-char VLAs
> and pointer to arrays.
> 
> Martin
> 
>>
>> OK for the trunk.
>> THanks,
>> Jeff
>>
> 
> 
> gcc-90662.diff
> 
> PR tree-optimization/90662 - strlen of a string in a vla plus offset not 
> folded
> 
> gcc/ChangeLog:
> 
>       PR tree-optimization/90662
>       * tree-ssa-strlen.c (get_stridx): Handle simple VLAs and pointers
>       to arrays.
> 
> gcc/testsuite/ChangeLog:
> 
>       PR tree-optimization/90662
>       * gcc.dg/strlenopt-62.c: New test.
>       * gcc.dg/strlenopt-63.c: New test.
>       * gcc.dg/strlenopt-64.c: New test.
OK
jeff

Reply via email to