public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65410] New: "Short local string array" optimization doesn't happen if string has NULs
@ 2015-03-12 19:08 vda.linux at googlemail dot com
2021-10-02 18:53 ` [Bug middle-end/65410] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: vda.linux at googlemail dot com @ 2015-03-12 19:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65410
Bug ID: 65410
Summary: "Short local string array" optimization doesn't happen
if string has NULs
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: vda.linux at googlemail dot com
void f(char *);
void g() {
char buf[12] = "1234567890";
f(buf);
}
In the above example, "gcc -O2" creates buf[12] with immediate stores:
subq $24, %rsp
movabsq $4050765991979987505, %rax
movq %rsp, %rdi
movq %rax, (%rsp)
movl $12345, 8(%rsp)
call f
addq $24, %rsp
ret
But if buf[] definition has \0 anywhere (for example, at the end where it does
not even change the semantics of the code), optimization is not happening, gcc
allocates a constant string and copies it into buf[]:
void f(char *);
void g() {
char buf[12] = "1234567890\0";
f(buf);
}
.section .rodata
.LC0:
.string "1234567890"
.string ""
.text
g:
subq $24, %rsp
movq .LC0(%rip), %rax
movq %rsp, %rdi
movq %rax, (%rsp)
movl .LC0+8(%rip), %eax
movl %eax, 8(%rsp)
call f
addq $24, %rsp
ret
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/65410] "Short local string array" optimization doesn't happen if string has NULs
2015-03-12 19:08 [Bug c/65410] New: "Short local string array" optimization doesn't happen if string has NULs vda.linux at googlemail dot com
@ 2021-10-02 18:53 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-02 18:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65410
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |9.0
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 9 by r9-2897-gd01b568a78351beb6b6.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-02 18:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 19:08 [Bug c/65410] New: "Short local string array" optimization doesn't happen if string has NULs vda.linux at googlemail dot com
2021-10-02 18:53 ` [Bug middle-end/65410] " 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).