diff options
author | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2021-11-15 23:03:13 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2021-11-16 04:19:51 +0530 |
commit | d1753b4be981fcb176f56b6ed45f7dbe1177d641 (patch) | |
tree | de2bb231db90865a3451fb4bcd592e51d86f9ccf /gcc/testsuite | |
parent | 4c19122bf5afa5cb479fd9445f0c591c52add09b (diff) | |
download | gcc-d1753b4be981fcb176f56b6ed45f7dbe1177d641.zip gcc-d1753b4be981fcb176f56b6ed45f7dbe1177d641.tar.gz gcc-d1753b4be981fcb176f56b6ed45f7dbe1177d641.tar.bz2 |
gimple-fold: Transform stp*cpy_chk to str*cpy directly
Avoid going through another folding cycle and use the ignore flag to
directly transform BUILT_IN_STPCPY_CHK to BUILT_IN_STRCPY when set,
likewise for BUILT_IN_STPNCPY_CHK to BUILT_IN_STPNCPY.
Dump the transformation in dump_file so that we can verify in tests that
the direct transformation actually happened.
gcc/ChangeLog:
* gimple-fold.c (dump_transformation): New function.
(gimple_fold_builtin_stxcpy_chk,
gimple_fold_builtin_stxncpy_chk): Use it. Simplify to
BUILT_IN_STRNCPY if return value is not used.
gcc/testsuite/ChangeLog:
* gcc.dg/fold-stringops-1.c: New test.
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-stringops-1.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/fold-stringops-1.c b/gcc/testsuite/gcc.dg/fold-stringops-1.c new file mode 100644 index 0000000..e26632a --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-stringops-1.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-lower-details" } */ + +char dst[2048]; + +char * +copy1 (const char *src, int cond) +{ + __builtin___stpncpy_chk (dst, src, 42, __builtin_object_size (dst, 0)); + + return dst; +} + +char * +copy2 (void) +{ + __builtin___stpcpy_chk (dst, "Hello world", __builtin_object_size (dst, 0)); + + return dst; +} +/* { dg-final { scan-tree-dump "simplified __builtin___stpncpy_chk to __builtin_strncpy" "lower" } } */ +/* { dg-final { scan-tree-dump "simplified __builtin___stpcpy_chk to __builtin_strcpy" "lower" } } */ + |