public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108626] New: GCC doesn't combine string literals for const char*const and const char b[]
@ 2023-02-01  9:50 marat at slonopotamus dot org
  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
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: marat at slonopotamus dot org @ 2023-02-01  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-07-24  2:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01  9:50 [Bug c++/108626] New: GCC doesn't combine string literals for const char*const and const char b[] marat at slonopotamus dot org
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

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).