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.

Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org>
---
 gcc/gimple-fold.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 74c9ce4bdc8..cadccfe3010 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -3176,7 +3176,7 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi,
     }
 
   /* If __builtin_st{r,p}cpy_chk is used, assume st{r,p}cpy is available.  */
-  fn = builtin_decl_explicit (fcode == BUILT_IN_STPCPY_CHK
+  fn = builtin_decl_explicit (fcode == BUILT_IN_STPCPY_CHK && !ignore
                              ? BUILT_IN_STPCPY : BUILT_IN_STRCPY);
   if (!fn)
     return false;
@@ -3220,7 +3220,7 @@ gimple_fold_builtin_stxncpy_chk (gimple_stmt_iterator 
*gsi,
     return false;
 
   /* If __builtin_st{r,p}ncpy_chk is used, assume st{r,p}ncpy is available.  */
-  fn = builtin_decl_explicit (fcode == BUILT_IN_STPNCPY_CHK
+  fn = builtin_decl_explicit (fcode == BUILT_IN_STPNCPY_CHK && !ignore
                              ? BUILT_IN_STPNCPY : BUILT_IN_STRNCPY);
   if (!fn)
     return false;
-- 
2.31.1

Reply via email to