+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>
PR target/86987
tree
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;
- if (c_strlen (exp, 1, &nonstr, 1) == NULL && nonstr)
- return nonstr;
-
- return NULL_TREE;
+ c_strlen (exp, 1, &nonstr);
+ return nonstr;
}
/* Compute the length of a null-terminated character string or wide
/* Avoid pointers to arrays (see bug 86622). */
if (POINTER_TYPE_P (TREE_TYPE (arg))
&& 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;
tree type = TREE_TYPE (arg1);
}
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))
array = arg;
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>
* gnat.dg/dinst.adb: Adjust for locviews.
T (&b[3][1] + 1); /* { dg-warning "nul" } */
T (&b[3][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] + i1); /* { dg-warning "nul" } */
T (&b[i3][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[1]);
T (&b[i3][i1]); /* { dg-warning "nul" } */
T (&b[i3][i1] + 1); /* { dg-warning "nul" } */
T (&b[i3][i1] + i1); /* { dg-warning "nul" } */
-T (&b[i3][v0]); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */
-T (&b[i3][i1] + v0); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */
-T (&b[i3][v0] + v1); /* { dg-warning "nul" "pr86919" { xfail *-*-* } } */
+T (&b[i3][v0]); /* { dg-warning "nul" } */
+T (&b[i3][i1] + v0); /* { dg-warning "nul" } */
+T (&b[i3][v0] + v1); /* { dg-warning "nul" } */
T (v0 ? "" : b[0]);
T (v0 ? "" : b[1]);
T (&s.b[i0]); /* { 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] + 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]; };