public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/112507] New: Missed optimization of strcpy(3) (or stpcpy(3)) with previous strnlen(3)
@ 2023-11-13 9:41 alx at kernel dot org
2023-11-13 18:41 ` [Bug tree-optimization/112507] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: alx at kernel dot org @ 2023-11-13 9:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112507
Bug ID: 112507
Summary: Missed optimization of strcpy(3) (or stpcpy(3)) with
previous strnlen(3)
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: alx at kernel dot org
Target Milestone: ---
The following code can be optimized to use memcpy(3), since the length
of the copy is known (we've just called strnlen(3), and discarded the
possibility of truncated lengths).
$ cat strxcpy.c
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
ssize_t
strxcpy(char *restrict dst, const char *restrict src, size_t dsize)
{
if (strnlen(src, dsize) == dsize)
return -1;
return stpcpy(dst, src) - dst;
}
This compiles to stpcpy(3). Similar code written with strcpy(3) also
keeps strcpy(3). But they could be optimized with mempcpy(3) or
memcpy(3).
On Mon, Nov 13, 2023 at 07:56:00AM +0100, Richard Biener wrote:
> It looks like a transform for the strlen pass.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/112507] Missed optimization of strcpy(3) (or stpcpy(3)) with previous strnlen(3)
2023-11-13 9:41 [Bug c/112507] New: Missed optimization of strcpy(3) (or stpcpy(3)) with previous strnlen(3) alx at kernel dot org
@ 2023-11-13 18:41 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 18:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112507
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-13 18:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13 9:41 [Bug c/112507] New: Missed optimization of strcpy(3) (or stpcpy(3)) with previous strnlen(3) alx at kernel dot org
2023-11-13 18:41 ` [Bug tree-optimization/112507] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).