diff options
author | Martin Sebor <msebor@redhat.com> | 2017-02-14 16:51:24 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2017-02-14 09:51:24 -0700 |
commit | bf00c9e08002fcb36d8b61d2e2a47801ef11c2f1 (patch) | |
tree | baaafc5e87557d7dd732a8365ba695cd92a0b830 /gcc/gimple-ssa-sprintf.c | |
parent | 355930ab262ceeb4dec0dd1094fd1dee8d9186c6 (diff) | |
download | gcc-bf00c9e08002fcb36d8b61d2e2a47801ef11c2f1.zip gcc-bf00c9e08002fcb36d8b61d2e2a47801ef11c2f1.tar.gz gcc-bf00c9e08002fcb36d8b61d2e2a47801ef11c2f1.tar.bz2 |
PR middle-end/79448 - unhelpful -Wformat-truncation=2 warning
gcc/testsuite/ChangeLog:
PR middle-end/79448
* gcc.dg/tree-ssa/builtin-snprintf-warn-3.c: New test.
* gcc.dg/tree-ssa/pr79448-2.c: New test.
* gcc.dg/tree-ssa/pr79448.c: New test.
gcc/ChangeLog:
PR middle-end/79448
* gimple-ssa-sprintf.c (format_directive): Avoid issuing INT_MAX
warning for strings of unknown length.
From-SVN: r245437
Diffstat (limited to 'gcc/gimple-ssa-sprintf.c')
-rw-r--r-- | gcc/gimple-ssa-sprintf.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index b2db8b8..a5fc3ff 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -2559,13 +2559,16 @@ format_directive (const pass_sprintf_length::call_info &info, res->range.max += fmtres.range.max; /* Raise the total unlikely maximum by the larger of the maximum - and the unlikely maximum. It doesn't matter if the unlikely - maximum overflows. */ + and the unlikely maximum. */ + unsigned HOST_WIDE_INT save = res->range.unlikely; if (fmtres.range.max < fmtres.range.unlikely) res->range.unlikely += fmtres.range.unlikely; else res->range.unlikely += fmtres.range.max; + if (res->range.unlikely < save) + res->range.unlikely = HOST_WIDE_INT_M1U; + res->range.min += fmtres.range.min; res->range.likely += fmtres.range.likely; @@ -2616,7 +2619,12 @@ format_directive (const pass_sprintf_length::call_info &info, /* Has the likely and maximum directive output exceeded INT_MAX? */ bool likelyximax = *dir.beg && res->range.likely > target_int_max (); - bool maxximax = *dir.beg && res->range.max > target_int_max (); + /* Don't consider the maximum to be in excess when it's the result + of a string of unknown length (i.e., whose maximum has been set + to be greater than or equal to HOST_WIDE_INT_MAX. */ + bool maxximax = (*dir.beg + && res->range.max > target_int_max () + && res->range.max < HOST_WIDE_INT_MAX); if (!warned /* Warn for the likely output size at level 1. */ |