public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "marat at slonopotamus dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108626] New: GCC doesn't combine string literals for const char*const and const char b[] Date: Wed, 01 Feb 2023 09:50:53 +0000 [thread overview] Message-ID: <bug-108626-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626 Bug ID: 108626 Summary: GCC doesn't combine string literals for const char*const and const char b[] Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: marat at slonopotamus dot org Target Milestone: --- Given the following code ---- #include <stdio.h> static const char* const a = "bla"; static const char b[] = "bla"; int main() { puts(a); puts(b); } ---- GCC 12.2 with -O2 produces ---- .LC0: .string "bla" main: sub rsp, 8 mov edi, OFFSET FLAT:.LC0 call puts mov edi, OFFSET FLAT:_ZL1b call puts xor eax, eax add rsp, 8 ret _ZL1b: .string "bla" ---- On the other hand, clang 15.0 with -O1 and higher produces ---- main: # @main push rbx lea rbx, [rip + .L.str] mov rdi, rbx call puts@PLT mov rdi, rbx call puts@PLT xor eax, eax pop rbx ret .L.str: .asciz "bla" ---- For some reason, GCC doesn't want to combine readonly data for these two string literals. Godbolt playground: https://godbolt.org/z/WaeazezE6
next reply other threads:[~2023-02-01 9:50 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-01 9:50 marat at slonopotamus dot org [this message] 2023-02-01 16:29 ` [Bug c++/108626] GCC doesn't deduplicate string literals for const char*const and const char[] pinskia at gcc dot gnu.org 2023-02-01 18:19 ` marat at slonopotamus dot org 2023-02-01 18:57 ` jakub at gcc dot gnu.org 2023-02-02 3:01 ` de34 at live dot cn 2023-02-02 10:09 ` marat at slonopotamus dot org 2023-02-02 11:36 ` de34 at live dot cn 2023-02-02 13:25 ` marat at slonopotamus dot org 2023-02-02 14:31 ` marat at slonopotamus dot org 2023-07-24 2:21 ` de34 at live dot cn
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108626-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).