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/tree.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/tree.c')
-rw-r--r-- | gcc/tree.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -11872,18 +11872,23 @@ build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size) } } -/* Create a new constant string literal consisting of elements of type - ELTYPE and return a tree node representing char* pointer to it as - an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). The STRING_CST value is - the LEN bytes at STR (the representation of the string, which may +/* Create a new constant string literal of type ELTYPE[SIZE] (or LEN + if SIZE == -1) and return a tree node representing char* pointer to + it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). The STRING_CST value + is the LEN bytes at STR (the representation of the string, which may be wide). */ tree build_string_literal (int len, const char *str, - tree eltype /* = char_type_node */) + tree eltype /* = char_type_node */, + unsigned HOST_WIDE_INT size /* = -1 */) { tree t = build_string (len, str); - tree index = build_index_type (size_int (len - 1)); + /* Set the maximum valid index based on the string length or SIZE. */ + unsigned HOST_WIDE_INT maxidx + = (size == HOST_WIDE_INT_M1U ? len : size) - 1; + + tree index = build_index_type (size_int (maxidx)); eltype = build_type_variant (eltype, 1, 0); tree type = build_array_type (eltype, index); TREE_TYPE (t) = type; |