Commit c7813484 by Jeff Law

re PR c/87387 (trunk/gcc/builtins.c:585:7: warning: -Wself-assign problem)

	PR c/87387
        * builtins.c (unterminated_array): Simplify.
	* expr.c (string_constant): Handle SSA_NAME.  Add more exceptions
	where pointer arithmetic is safe.

	* gcc.dg/warn-stpcpy-no-nul.c: Drop unnecessary xfails.
	* gcc.dg/warn-stplen-no-nul.c: Likewise.

From-SVN: r264585
parent a9f6e019
2018-09-25 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR c/87387
* builtins.c (unterminated_array): Simplify.
* expr.c (string_constant): Handle SSA_NAME. Add more exceptions
where pointer arithmetic is safe.
2018-09-25 Segher Boessenkool <segher@kernel.crashing.org> 2018-09-25 Segher Boessenkool <segher@kernel.crashing.org>
PR target/86987 PR target/86987
......
...@@ -570,28 +570,9 @@ warn_string_no_nul (location_t loc, const char *fn, tree arg, tree decl) ...@@ -570,28 +570,9 @@ warn_string_no_nul (location_t loc, const char *fn, tree arg, tree decl)
tree tree
unterminated_array (tree exp) unterminated_array (tree exp)
{ {
if (TREE_CODE (exp) == SSA_NAME)
{
gimple *stmt = SSA_NAME_DEF_STMT (exp);
if (!is_gimple_assign (stmt))
return NULL_TREE;
tree rhs1 = gimple_assign_rhs1 (stmt);
tree_code code = gimple_assign_rhs_code (stmt);
if (code == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (rhs1, 0)) == ARRAY_REF)
rhs1 = rhs1;
else if (code != POINTER_PLUS_EXPR)
return NULL_TREE;
exp = rhs1;
}
tree nonstr = NULL; tree nonstr = NULL;
if (c_strlen (exp, 1, &nonstr, 1) == NULL && nonstr) c_strlen (exp, 1, &nonstr);
return nonstr; return nonstr;
return NULL_TREE;
} }
/* Compute the length of a null-terminated character string or wide /* Compute the length of a null-terminated character string or wide
......
...@@ -11372,7 +11372,10 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) ...@@ -11372,7 +11372,10 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
/* Avoid pointers to arrays (see bug 86622). */ /* Avoid pointers to arrays (see bug 86622). */
if (POINTER_TYPE_P (TREE_TYPE (arg)) if (POINTER_TYPE_P (TREE_TYPE (arg))
&& TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) == ARRAY_TYPE && TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) == ARRAY_TYPE
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == ARRAY_REF) && !(decl && !*decl)
&& !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
&& mem_size && tree_fits_uhwi_p (*mem_size)
&& tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
return NULL_TREE; return NULL_TREE;
tree type = TREE_TYPE (arg1); tree type = TREE_TYPE (arg1);
...@@ -11381,6 +11384,38 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) ...@@ -11381,6 +11384,38 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
} }
return NULL_TREE; return NULL_TREE;
} }
else if (TREE_CODE (arg) == SSA_NAME)
{
gimple *stmt = SSA_NAME_DEF_STMT (arg);
if (!is_gimple_assign (stmt))
return NULL_TREE;
tree rhs1 = gimple_assign_rhs1 (stmt);
tree_code code = gimple_assign_rhs_code (stmt);
if (code == ADDR_EXPR)
return string_constant (rhs1, ptr_offset, mem_size, decl);
else if (code != POINTER_PLUS_EXPR)
return NULL_TREE;
tree offset;
if (tree str = string_constant (rhs1, &offset, mem_size, decl))
{
/* Avoid pointers to arrays (see bug 86622). */
if (POINTER_TYPE_P (TREE_TYPE (rhs1))
&& TREE_CODE (TREE_TYPE (TREE_TYPE (rhs1))) == ARRAY_TYPE
&& !(decl && !*decl)
&& !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
&& mem_size && tree_fits_uhwi_p (*mem_size)
&& tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
return NULL_TREE;
tree rhs2 = gimple_assign_rhs2 (stmt);
tree type = TREE_TYPE (rhs2);
*ptr_offset = fold_build2 (PLUS_EXPR, type, offset, rhs2);
return str;
}
return NULL_TREE;
}
else if (DECL_P (arg)) else if (DECL_P (arg))
array = arg; array = arg;
else else
......
2018-09-25 Jeff Law <law@redhat.com>
* gcc.dg/warn-stpcpy-no-nul.c: Drop unnecessary xfails.
* gcc.dg/warn-stplen-no-nul.c: Likewise.
2018-09-25 Alexandre Oliva <oliva@adacore.com> 2018-09-25 Alexandre Oliva <oliva@adacore.com>
* gnat.dg/dinst.adb: Adjust for locviews. * gnat.dg/dinst.adb: Adjust for locviews.
......
...@@ -71,13 +71,13 @@ void test_two_dim_array (char *d) ...@@ -71,13 +71,13 @@ void test_two_dim_array (char *d)
T (&b[3][1] + 1); /* { dg-warning "nul" } */ T (&b[3][1] + 1); /* { dg-warning "nul" } */
T (&b[3][v0]); /* { dg-warning "nul" } */ T (&b[3][v0]); /* { dg-warning "nul" } */
T (&b[3][1] + v0); /* { dg-warning "nul" } */ T (&b[3][1] + v0); /* { dg-warning "nul" } */
T (&b[3][v0] + v1); /* { dg-warning "nul" "bug ???" { xfail *-*-* } } */ T (&b[3][v0] + v1); /* { dg-warning "nul" } */
T (&b[i3][i1]); /* { dg-warning "nul" } */ T (&b[i3][i1]); /* { dg-warning "nul" } */
T (&b[i3][i1] + i1); /* { dg-warning "nul" } */ T (&b[i3][i1] + i1); /* { dg-warning "nul" } */
T (&b[i3][v0]); /* { dg-warning "nul" } */ T (&b[i3][v0]); /* { dg-warning "nul" } */
T (&b[i3][i1] + v0); /* { dg-warning "nul" } */ T (&b[i3][i1] + v0); /* { dg-warning "nul" } */
T (&b[i3][v0] + v1); /* { dg-warning "nul" "bug ???" { xfail *-*-* } } */ T (&b[i3][v0] + v1); /* { dg-warning "nul" } */
T (v0 ? "" : b[0]); T (v0 ? "" : b[0]);
T (v0 ? "" : b[1]); T (v0 ? "" : b[1]);
......
...@@ -71,9 +71,9 @@ T (&b[3][v0] + v1); /* { dg-warning "nul" } */ ...@@ -71,9 +71,9 @@ T (&b[3][v0] + v1); /* { dg-warning "nul" } */
T (&b[i3][i1]); /* { dg-warning "nul" } */ T (&b[i3][i1]); /* { dg-warning "nul" } */
T (&b[i3][i1] + 1); /* { dg-warning "nul" } */ T (&b[i3][i1] + 1); /* { dg-warning "nul" } */
T (&b[i3][i1] + i1); /* { dg-warning "nul" } */ T (&b[i3][i1] + i1); /* { dg-warning "nul" } */
T (&b[i3][v0]); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */ T (&b[i3][v0]); /* { dg-warning "nul" } */
T (&b[i3][i1] + v0); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */ T (&b[i3][i1] + v0); /* { dg-warning "nul" } */
T (&b[i3][v0] + v1); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */ T (&b[i3][v0] + v1); /* { dg-warning "nul" } */
T (v0 ? "" : b[0]); T (v0 ? "" : b[0]);
T (v0 ? "" : b[1]); T (v0 ? "" : b[1]);
...@@ -152,10 +152,10 @@ T (&s.b[1] + v0); /* { dg-warning "nul" } */ ...@@ -152,10 +152,10 @@ T (&s.b[1] + v0); /* { dg-warning "nul" } */
T (&s.b[i0]); /* { dg-warning "nul" } */ T (&s.b[i0]); /* { dg-warning "nul" } */
T (&s.b[i0] + i1); /* { dg-warning "nul" } */ T (&s.b[i0] + i1); /* { dg-warning "nul" } */
T (&s.b[i0] + v0); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */ T (&s.b[i0] + v0); /* { dg-warning "nul" } */
T (&s.b[i1]); /* { dg-warning "nul" } */ T (&s.b[i1]); /* { dg-warning "nul" } */
T (&s.b[i1] + i1); /* { dg-warning "nul" } */ T (&s.b[i1] + i1); /* { dg-warning "nul" } */
T (&s.b[i1] + v0); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */ T (&s.b[i1] + v0); /* { dg-warning "nul" } */
struct B { struct A a[2]; }; struct B { struct A a[2]; };
......
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