PR middle-end/78622 - -Wformat-length/-fprintf-return-value incorrect with overflow...
authorMartin Sebor <msebor@redhat.com>
Mon, 12 Dec 2016 21:56:22 +0000 (21:56 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 12 Dec 2016 21:56:22 +0000 (14:56 -0700)
commit573aa7d4b7c1249c16c12c8483ab8b9830848b82
tree0db314e59f7a48d91b36bc70196945369abde7e7
parent068b961b6a5ad37898cee76ce0e80ef46001eb03
PR middle-end/78622 - -Wformat-length/-fprintf-return-value incorrect with overflow/wrapping

gcc/ChangeLog:

PR middle-end/78622
PR middle-end78606
* gimple-ssa-sprintf.c (min_bytes_remaining): Use res.knownrange
rather than res.bounded.
(get_width_and_precision): Set precision to -1 when negative.
(adjust_range_for_overflow): New function.
(format_integer): Correct the handling of the space, plus, and pound
flags, and the special case of zero precision.
Always set res.bounded to true unless either precision or width
is specified and unknown.
Call adjust_range_for_overflow.
Avoid use zero as the shortest value when precision is specified
but unknown.
(format_directive): Remove vestigial quoting.  Always inform of
argument value or range when it's available.
(add_bytes): Correct the computation of boundrange used to
decide whether a warning is of a "maybe" or "defnitely" kind.

gcc/testsuite/ChangeLog:

PR middle-end/78622
PR middle-end78606
* gcc.c-torture/execute/pr78622.c: New test.
* gcc.dg/tree-ssa/builtin-sprintf-2.c: Remove "benign" undefined
behavior inadvertently introduced in a previous commit.  Tighten
up final checking.
* gcc.dg/tree-ssa/builtin-sprintf-5.c: Rename macros for clarity.
Add test cases.
* gcc.dg/tree-ssa/builtin-sprintf-6.c: Add test cases.
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Same.
* gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: Same.
* gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: Same.
* gcc.dg/tree-ssa/builtin-sprintf-warn-5.c: Same.
* gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: Remove xfails and
add a final optimization check.
* gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases.
* gcc.dg/tree-ssa/pr78622.c: New test.

From-SVN: r243582
13 files changed:
gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr78622.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-5.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-6.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-2.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-3.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf.c
gcc/testsuite/gcc.dg/tree-ssa/pr78622.c [new file with mode: 0644]