]> gcc.gnu.org Git - gcc.git/commit
Correct handling of constant representations containing embedded nuls (backport from...
authorMartin Sebor <msebor@redhat.com>
Thu, 8 Oct 2020 18:35:01 +0000 (12:35 -0600)
committerMartin Sebor <msebor@redhat.com>
Thu, 8 Oct 2020 18:35:01 +0000 (12:35 -0600)
commite4c9aac98611f63847ef6c57916808d9a2d7abcb
treea709be9c2aee4cf4e956d6547ca04ffdfd9f7830
parentd4ec0a15afb7538247206aa9936071544fd860f8
Correct handling of constant representations containing embedded nuls (backport from trunk).

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
This page took 0.083789 seconds and 6 git commands to generate.