Commit 715fcd73 by Martin Sebor Committed by Martin Sebor

PR tree-optimization/86400 - set<string>::set<char (*)[2]) constructor does not…

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
parent 09cff37b
2018-07-05 Martin Sebor <msebor@redhat.com>
PR c++/86400
* 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.
2018-07-05 Nathan Sidwell <nathan@acm.org> 2018-07-05 Nathan Sidwell <nathan@acm.org>
Replace NO_IMPLICIT_EXTERN_C with SYSTEM_IMPLICIT_EXTERN_C. Replace NO_IMPLICIT_EXTERN_C with SYSTEM_IMPLICIT_EXTERN_C.
......
2018-07-05 Martin Sebor <msebor@redhat.com>
PR c++/86400
* gcc.dg/strlenopt-47.c: New test.
* gcc.dg/strlenopt-48.c: New test.
2018-07-05 Tamar Christina <tamar.christina@arm.com> 2018-07-05 Tamar Christina <tamar.christina@arm.com>
PR target/84711 PR target/84711
......
/* PR tree-optimization/86400 - set<string>::set<char (*)[2]) constructor
does not work with array argument
Verify that strlen() calls with two-character array elements of
multidimensional arrays whose higher order dimension is 1 are not
folded.
{ dg-do compile }
{ dg-options "-O2 -Wall -fdump-tree-optimized" } */
#include "strlenopt.h"
void f (void)
{
extern char a[1][2];
int n = strlen (*a);
if (n != 1)
abort();
}
void g (void)
{
extern char b[1][2];
int n = strlen (b[0]);
if (n != 1)
abort();
}
void h (void)
{
extern char c[1][2];
int n = strlen (&c[0][0]);
if (n != 1)
abort();
}
/* { dg-final { scan-tree-dump-times "= strlen" 3 "optimized" } }
{ dg-final { scan-tree-dump-times "abort" 3 "optimized" } } */
/* PR tree-optimization/86400 - set<string>::set<char (*)[2]) constructor
does not work with array argument
Verify that strlen() calls with one-character array elements of
multidimensional arrays are still folded.
{ dg-do compile }
{ dg-options "-O2 -Wall -fdump-tree-optimized" } */
#include "strlenopt.h"
void f (void)
{
extern char a[2][1];
int n = strlen (a[1]);
if (n)
abort();
}
void g (void)
{
extern char b[3][2][1];
int n = strlen (b[2][1]);
if (n)
abort();
}
void h (void)
{
extern char c[4][3][2][1];
int n = strlen (c[3][2][1]);
if (n)
abort();
}
/* { dg-final { scan-tree-dump-times "strlen" 0 "optimized" } }
{ dg-final { scan-tree-dump-times "abort" 0 "optimized" } } */
...@@ -1156,22 +1156,17 @@ maybe_set_strlen_range (tree lhs, tree src, tree bound) ...@@ -1156,22 +1156,17 @@ maybe_set_strlen_range (tree lhs, tree src, tree bound)
if (src_is_array && !array_at_struct_end_p (src)) if (src_is_array && !array_at_struct_end_p (src))
{ {
tree type = TREE_TYPE (src); tree type = TREE_TYPE (src);
if (tree dom = TYPE_DOMAIN (type)) if (tree size = TYPE_SIZE_UNIT (type))
{ if (size && TREE_CODE (size) == INTEGER_CST)
tree maxval = TYPE_MAX_VALUE (dom); max = wi::to_wide (size);
if (maxval)
max = wi::to_wide (maxval); /* For strlen() the upper bound above is equal to
else the longest string that can be stored in the array
max = wi::zero (min.get_precision ()); (i.e., it accounts for the terminating nul. For
strnlen() bump up the maximum by one since the array
/* For strlen() the upper bound above is equal to need not be nul-terminated. */
the longest string that can be stored in the array if (!bound && max != 0)
(i.e., it accounts for the terminating nul. For --max;
strnlen() bump up the maximum by one since the array
need not be nul-terminated. */
if (bound)
++max;
}
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment