diff options
author | Martin Sebor <msebor@redhat.com> | 2018-07-05 14:36:09 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-07-05 08:36:09 -0600 |
commit | 715fcd73b66c639d9e0e3f3ef9c6ff9d621d7131 (patch) | |
tree | bf5e2c54a9f08d3e851b7523146bc2c9d4cc8238 /gcc/tree-ssa-strlen.c | |
parent | 09cff37bfdcc9407a72262cbdd6fd3350488d934 (diff) | |
download | gcc-715fcd73b66c639d9e0e3f3ef9c6ff9d621d7131.zip gcc-715fcd73b66c639d9e0e3f3ef9c6ff9d621d7131.tar.gz gcc-715fcd73b66c639d9e0e3f3ef9c6ff9d621d7131.tar.bz2 |
PR tree-optimization/86400 - set<string>::set<char (*)[2]) constructor does not work with array argument
gcc/ChangeLog:
* tree-ssa-strlen.c (maybe_set_strlen_range): Use type size rather
than its domain to compute its the upper bound of a char array.
gcc/testsuite/ChangeLog:
* gcc.dg/strlenopt-47.c: New test.
* gcc.dg/strlenopt-48.c: New test.
From-SVN: r262438
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 5807c79..736e2d9 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1156,22 +1156,17 @@ maybe_set_strlen_range (tree lhs, tree src, tree bound) if (src_is_array && !array_at_struct_end_p (src)) { tree type = TREE_TYPE (src); - if (tree dom = TYPE_DOMAIN (type)) - { - tree maxval = TYPE_MAX_VALUE (dom); - if (maxval) - max = wi::to_wide (maxval); - else - max = wi::zero (min.get_precision ()); - - /* For strlen() the upper bound above is equal to - the longest string that can be stored in the array - (i.e., it accounts for the terminating nul. For - strnlen() bump up the maximum by one since the array - need not be nul-terminated. */ - if (bound) - ++max; - } + if (tree size = TYPE_SIZE_UNIT (type)) + if (size && TREE_CODE (size) == INTEGER_CST) + max = wi::to_wide (size); + + /* For strlen() the upper bound above is equal to + the longest string that can be stored in the array + (i.e., it accounts for the terminating nul. For + strnlen() bump up the maximum by one since the array + need not be nul-terminated. */ + if (!bound && max != 0) + --max; } else { |