aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-ssa-sprintf.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2017-02-03 16:38:15 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2017-02-03 09:38:15 -0700
commit3f3430400b2ce552a5dbdae49a3a482687b96afa (patch)
treec78749d08d207350d71edfc1c5b9871d422a1f1c /gcc/gimple-ssa-sprintf.c
parent46a2ab580a762b0fc3e64dc4ab24d459a4bd1fd2 (diff)
downloadgcc-3f3430400b2ce552a5dbdae49a3a482687b96afa.zip
gcc-3f3430400b2ce552a5dbdae49a3a482687b96afa.tar.gz
gcc-3f3430400b2ce552a5dbdae49a3a482687b96afa.tar.bz2
PR tree-optimization/79352 - -fprintf-return-value doesn't handle flexible-like array members properly
gcc/ChangeLog: PR tree-optimization/79352 * gimple-fold.c (get_range_strlen): Add argument. (get_range_strlen): Change return type to bool. (get_maxval_strlen): Pass in a dummy argument. * gimple-fold.h (get_range_strlen): Change return type to bool. * gimple-ssa-sprintf.c (get_string_length): Set unlikely counter. * tree.h (array_at_struct_end_p): Add argument. * tree.c (array_at_struct_end_p): Handle it. gcc/testsuite/ChangeLog: PR tree-optimization/79352 * gcc.dg/tree-ssa/pr79352.c: New test. From-SVN: r245156
Diffstat (limited to 'gcc/gimple-ssa-sprintf.c')
-rw-r--r--gcc/gimple-ssa-sprintf.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 10c6d8e..3670bac 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -1800,7 +1800,7 @@ get_string_length (tree str)
aren't known to point any such arrays result in LENRANGE[1] set
to SIZE_MAX. */
tree lenrange[2];
- get_range_strlen (str, lenrange);
+ bool flexarray = get_range_strlen (str, lenrange);
if (lenrange [0] || lenrange [1])
{
@@ -1843,7 +1843,11 @@ get_string_length (tree str)
res.range.min = 0;
}
- res.range.unlikely = res.range.max;
+ /* If the range of string length has been estimated from the size
+ of an array at the end of a struct assume that it's longer than
+ the array bound says it is in case it's used as a poor man's
+ flexible array member, such as in struct S { char a[4]; }; */
+ res.range.unlikely = flexarray ? HOST_WIDE_INT_MAX : res.range.max;
return res;
}