From 3f3430400b2ce552a5dbdae49a3a482687b96afa Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Fri, 3 Feb 2017 16:38:15 +0000 Subject: 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 --- gcc/gimple-ssa-sprintf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gcc/gimple-ssa-sprintf.c') 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; } -- cgit v1.1