gimple-fold: Use ranges to simplify strncat and snprintf
commit323026c7dfe23e1093e80f7db5f4851d1a867b62
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 15 Nov 2021 17:33:15 +0000 (15 23:03 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 15 Nov 2021 22:50:46 +0000 (16 04:20 +0530)
tree50e43bf3d1fb56115469cc2cf6fbb859015267a3
parentcea4dab861bae6536dd5655a42d73f2c17f655f7
gimple-fold: Use ranges to simplify strncat and snprintf

Use ranges for lengths and object sizes in strncat and snprintf to
determine if they can be transformed into simpler operations.

gcc/ChangeLog:

* gimple-fold.c (gimple_fold_builtin_strncat): Use ranges to
determine if it is safe to transform to strcat.
(gimple_fold_builtin_snprintf): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/fold-stringops-2.c: Define size_t.
(safe1): Adjust.
(safe4): New test.
* gcc.dg/fold-stringops-3.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/gimple-fold.c
gcc/testsuite/gcc.dg/fold-stringops-2.c
gcc/testsuite/gcc.dg/fold-stringops-3.c [new file with mode: 0644]