Commit d1af2f66 by Martin Sebor Committed by Martin Sebor

PR tree-optimization/86914 - wrong code with strlen() of poor-man's flexible…

PR tree-optimization/86914 - wrong code with strlen() of poor-man's flexible array member plus offset

gcc/ChangeLog:

	PR tree-optimization/86914
	* tree-ssa-strlen.c (maybe_set_strlen_range): Avoid MEM_REF.

gcc/testsuite/ChangeLog:

	PR tree-optimization/86914
	* gcc.dg/strlenopt-57.c: New test.

From-SVN: r263905
parent 37223543
2018-08-27 Martin Sebor <msebor@redhat.com>
PR tree-optimization/86914
* tree-ssa-strlen.c (maybe_set_strlen_range): Avoid MEM_REF.
2018-08-27 Martin Sebor <msebor@redhat.com>
PR tree-optimization/87112
* builtins.c (expand_builtin_strnlen): Convert c_strlen result to
the type of the bound argument.
......
2018-08-27 Martin Sebor <msebor@redhat.com>
PR tree-optimization/86914
* gcc.dg/strlenopt-57.c: New test.
2018-08-27 Martin Sebor <msebor@redhat.com>
PR tree-optimization/87112
* gcc.dg/pr87112.c: New test.
......
/* PR tree-optimization/86914 - wrong code with strlen() of poor-man's
flexible array member plus offset
{ dg-do compile }
{ dg-options "-O2 -Wall -fdump-tree-optimized" } */
#include "strlenopt.h"
struct A0 { char i, a[0]; };
struct A1 { char i, a[1]; };
struct A9 { char i, a[9]; };
struct Ax { char i, a[]; };
extern int a[];
extern struct A0 a0;
extern struct A1 a1;
extern struct A9 a9;
extern struct Ax ax;
void test_var_flexarray_cst_off (void)
{
/* Use arbitrary constants greater than 16 in case GCC ever starts
unrolling strlen() calls with small array arguments. */
a[0] = 17 < strlen (a0.a + 1);
a[1] = 19 < strlen (a1.a + 1);
a[2] = 23 < strlen (a9.a + 9);
a[3] = 29 < strlen (ax.a + 3);
}
void test_ptr_flexarray_cst_off (struct A0 *p0, struct A1 *p1,
struct A9 *p9, struct Ax *px)
{
a[0] = 17 < strlen (p0->a + 1);
a[1] = 19 < strlen (p1->a + 1);
a[2] = 23 < strlen (p9->a + 9);
a[3] = 29 < strlen (px->a + 3);
}
void test_ptr_flexarray_var_off (struct A0 *p0, struct A1 *p1,
struct A9 *p9, struct Ax *px,
int i)
{
a[0] = 17 < strlen (p0->a + i);
a[1] = 19 < strlen (p1->a + i);
a[2] = 23 < strlen (p9->a + i);
a[3] = 29 < strlen (px->a + i);
}
/* { dg-final { scan-tree-dump-times "strlen" 12 "optimized" } } */
......@@ -1160,7 +1160,9 @@ maybe_set_strlen_range (tree lhs, tree src, tree bound)
suggests if it's treated as a poor-man's flexible array member. */
src = TREE_OPERAND (src, 0);
bool src_is_array = TREE_CODE (TREE_TYPE (src)) == ARRAY_TYPE;
if (src_is_array && !array_at_struct_end_p (src))
if (src_is_array
&& TREE_CODE (src) != MEM_REF
&& !array_at_struct_end_p (src))
{
tree type = TREE_TYPE (src);
if (tree size = TYPE_SIZE_UNIT (type))
......
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