On 11/10/21 16:15, Siddhesh Poyarekar wrote:
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_safe): New function.
        (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/builtin-chk-fold.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org>
---
Changes from v1:
- Update comment that incorrectly said that known_safe emits a warning.
- Add tests for strncpy and snprintf too.

Sorry, this is failing some torture tests. I'll fix up and send another version.

Siddhesh

Reply via email to