diff options
author | Martin Sebor <msebor@redhat.com> | 2020-07-20 12:06:18 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2020-07-20 12:08:58 -0600 |
commit | d5803b9876b3d11c93d1a10fabb3fbb1c4a14bd6 (patch) | |
tree | 21c9c55bfd9003436d22c960d3578579af9dd744 /gcc/expr.c | |
parent | 3e99ed65cbedf7a6c0abb9cd63c191326995fd34 (diff) | |
download | gcc-d5803b9876b3d11c93d1a10fabb3fbb1c4a14bd6.zip gcc-d5803b9876b3d11c93d1a10fabb3fbb1c4a14bd6.tar.gz gcc-d5803b9876b3d11c93d1a10fabb3fbb1c4a14bd6.tar.bz2 |
Correct handling of constant representations containing embedded nuls.
Resolves:
PR middle-end/95189 - memcmp being wrongly stripped like strcm
PR middle-end/95886 - suboptimal memcpy with embedded zero bytes
gcc/ChangeLog:
PR middle-end/95189
PR middle-end/95886
* builtins.c (inline_expand_builtin_string_cmp): Rename...
(inline_expand_builtin_bytecmp): ...to this.
(builtin_memcpy_read_str): Don't expect data to be nul-terminated.
(expand_builtin_memory_copy_args): Handle object representations
with embedded nul bytes.
(expand_builtin_memcmp): Same.
(expand_builtin_strcmp): Adjust call to naming change.
(expand_builtin_strncmp): Same.
* expr.c (string_constant): Create empty strings with nonzero size.
* fold-const.c (c_getstr): Rename locals and update comments.
* tree.c (build_string): Accept null pointer argument.
(build_string_literal): Same.
* tree.h (build_string): Provide a default.
(build_string_literal): Same.
gcc/testsuite/ChangeLog:
PR middle-end/95189
PR middle-end/95886
* gcc.dg/memcmp-pr95189.c: New test.
* gcc.dg/strncmp-3.c: New test.
* gcc.target/i386/memcpy-pr95886.c: New test.
Diffstat (limited to 'gcc/expr.c')
-rw-r--r-- | gcc/expr.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -11829,12 +11829,12 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) while (TREE_CODE (chartype) == ARRAY_TYPE) chartype = TREE_TYPE (chartype); /* Convert a char array to an empty STRING_CST having an array - of the expected type. */ + of the expected type and size. */ if (!initsize) initsize = integer_zero_node; unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize); - init = build_string_literal (size ? 1 : 0, "", chartype, size); + init = build_string_literal (size, NULL, chartype, size); init = TREE_OPERAND (init, 0); init = TREE_OPERAND (init, 0); |