Correct handling of constant representations containing embedded nuls.
authorMartin Sebor <msebor@redhat.com>
Mon, 20 Jul 2020 18:06:18 +0000 (12:06 -0600)
committerMartin Sebor <msebor@redhat.com>
Mon, 20 Jul 2020 18:08:58 +0000 (12:08 -0600)
commitd5803b9876b3d11c93d1a10fabb3fbb1c4a14bd6
tree21c9c55bfd9003436d22c960d3578579af9dd744
parent3e99ed65cbedf7a6c0abb9cd63c191326995fd34
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.
gcc/builtins.c
gcc/expr.c
gcc/fold-const.c
gcc/testsuite/gcc.dg/memcmp-pr95189.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strncmp-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/memcpy-pr95886.c [new file with mode: 0644]
gcc/tree.c
gcc/tree.h