]> git.ipfire.org Git - thirdparty/gcc.git/commit
gimple-fold: Use ranges to simplify _chk calls
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 15 Nov 2021 17:33:14 +0000 (23:03 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Mon, 15 Nov 2021 22:50:31 +0000 (04:20 +0530)
commitcea4dab861bae6536dd5655a42d73f2c17f655f7
tree205fe929f25b0dc3b051f1f72a11b3e71bf101e3
parentd1753b4be981fcb176f56b6ed45f7dbe1177d641
gimple-fold: Use ranges to simplify _chk calls

Instead of comparing LEN and SIZE only if they are constants, use their
ranges to decide if LEN will always be lower than or same as SIZE.

This change ends up putting the stringop-overflow warning line number
against the strcpy implementation, so adjust the warning check to be
line number agnostic.

gcc/ChangeLog:

* gimple-fold.c (known_lower): New function.
(gimple_fold_builtin_strncat_chk,
gimple_fold_builtin_memory_chk, gimple_fold_builtin_stxcpy_chk,
gimple_fold_builtin_stxncpy_chk,
gimple_fold_builtin_snprintf_chk,
gimple_fold_builtin_sprintf_chk): Use it.

gcc/testsuite/ChangeLog:

* gcc.dg/Wobjsize-1.c: Make warning change line agnostic.
* gcc.dg/fold-stringops-2.c: New test.

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