[PATCH] gimple-fold: Transform stp*cpy_chk to strcpy

Siddhesh Poyarekar siddhesh@gotplt.org
Thu Nov 11 05:29:06 GMT 2021

On 11/11/21 02:06, Jeff Law wrote:
> On 11/10/2021 10:47 AM, Siddhesh Poyarekar wrote:
>> Use the ignore flag to transform BUILT_IN_STPCPY_CHK to BUILT_IN_STRCPY
>> when set.  This transformation will happen in a subsequent fold anyway
>> but do it right away and save the additional effort.
>> gcc/ChangeLog:
>>     * gimple-fold.c (gimple_fold_builtin_stxcpy_chk,
>>     gimple_fold_builtin_stxncpy_chk): Use BUILT_IN_STRNCPY if return
>>     value is not used.
> OK.
> Note we usually want testcases for this kind of stuff too.  It's not 
> strictly necessary, but it's hard to go wrong if you're including a test 
> that verifies your transformation happens at the point where you expect 
> it to happen.

I started looking at how I would write a test for this since the folder 
would recursively simplify the statement in the same pass and realized 
that the transformation sequence during lowering is __stpncpy_chk -> 
__strncpy_chk -> __strncpy.  As a result the transformation I'm trying 
to do already will have happened higher up.  I'm testing an updated 
patch that avoids having to fold twice and go directly from 
__stpncpy_chk -> __strncpy.


More information about the Gcc-patches mailing list