diff options
author | Martin Sebor <msebor@redhat.com> | 2019-08-22 23:09:26 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-08-22 17:09:26 -0600 |
commit | 14b7950f126f84fa585e3a057940ff10d4c5b3f8 (patch) | |
tree | 12d343894aea62b7964a5f595ddfd3cac40750e6 /gcc/gimple-fold.c | |
parent | 1b1e13dbde7f3eef0f8356af05c5de1fb46cb31b (diff) | |
download | gcc-14b7950f126f84fa585e3a057940ff10d4c5b3f8.zip gcc-14b7950f126f84fa585e3a057940ff10d4c5b3f8.tar.gz gcc-14b7950f126f84fa585e3a057940ff10d4c5b3f8.tar.bz2 |
PR middle-end/91490 - bogus argument missing terminating nul warning on strlen of a flexible array member
gcc/c-family/ChangeLog:
PR middle-end/91490
* c-common.c (braced_list_to_string): Add argument and overload.
Handle flexible length arrays and unions.
gcc/testsuite/ChangeLog:
PR middle-end/91490
* c-c++-common/Warray-bounds-7.c: New test.
* gcc.dg/Warray-bounds-39.c: Expect either -Warray-bounds or
-Wstringop-overflow.
* gcc.dg/strlenopt-78.c: New test.
gcc/ChangeLog:
PR middle-end/91490
* builtins.c (c_strlen): Rename argument and introduce new local.
Set no-warning bit on original argument.
* expr.c (string_constant): Pass argument type to fold_ctor_reference.
Fold empty and zero constructors into empty strings.
* gimple-fold.c (fold_nonarray_ctor_reference): Return a STRING_CST
for missing initializers.
* tree.c (build_string_literal): Handle optional argument.
* tree.h (build_string_literal): Add defaulted argument.
* gimple-ssa-warn-restrict.c (maybe_diag_access_bounds): Check
no-warning bit on original expression.
From-SVN: r274837
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index d576b08..fcffb98 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -759,11 +759,13 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, dest_align = get_pointer_alignment (dest); if (tree_fits_uhwi_p (len) && compare_tree_int (len, MOVE_MAX) <= 0 - /* ??? Don't transform copies from strings with known length this - confuses the tree-ssa-strlen.c. This doesn't handle - the case in gcc.dg/strlenopt-8.c which is XFAILed for that - reason. */ - && !c_strlen (src, 2) + /* FIXME: Don't transform copies from strings with known length. + Until GCC 9 this prevented a case in gcc.dg/strlenopt-8.c + from being handled, and the case was XFAILed for that reason. + Now that it is handled and the XFAIL removed, as soon as other + strlenopt tests that rely on it for passing are adjusted, this + hack can be removed. */ + && !c_strlen (src, 1) && !((tmp_str = c_getstr (src, &tmp_len)) != NULL && memchr (tmp_str, 0, tmp_len) == NULL)) { @@ -6969,12 +6971,15 @@ fold_nonarray_ctor_reference (tree type, tree ctor, from_decl, suboff); } } - /* Memory not explicitly mentioned in constructor is 0. */ - return type ? build_zero_cst (type) : NULL_TREE; + + if (!type) + return NULL_TREE; + + return build_zero_cst (type); } /* CTOR is value initializing memory. Fold a reference of TYPE and - bit size POLY_SIZE to the memory at bit POLY_OFFSET. When SIZE + bit size POLY_SIZE to the memory at bit POLY_OFFSET. When POLY_SIZE is zero, attempt to fold a reference to the entire subobject which OFFSET refers to. This is used when folding accesses to string members of aggregates. When non-null, set *SUBOFF to |