public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108257] New: Incorrect (non-unique) mangling of structured binding's backing variable
@ 2022-12-31 16:01 arthur.j.odwyer at gmail dot com
  2022-12-31 20:06 ` [Bug c++/108257] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2022-12-31 16:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108257

            Bug ID: 108257
           Summary: Incorrect (non-unique) mangling of structured
                    binding's backing variable
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

C++20 permits structured bindings (decomposition declarations) to be `static`.
This means we can use them in inline functions, where they need to be mangled
in the context of that inline function. Clang seems to get this right; GCC
forgets to include the context.

// https://godbolt.org/z/aKanscav3
struct A { int x,y; };
inline int f() {
    static auto [a,b] = A{1,2};
    return a;
}
inline int g() {
    static auto [a,b] = A{3,4};
    return a;
}
int (*pf)() = f;
int (*pg)() = g;
int main() {
    printf("%d %d\n", f(), g());
    printf("%d %d\n", pf(), pg());
}

This program should print "1 3" twice. On GCC, it fails to assemble, because
the symbol name `_ZNDC1a1bEE` is used for both backing variables.
On Clang, the symbol names are `_ZZ1fvEDC1a1bE` and `_ZZ1gvEDC1a1bE` instead.

(Totally off-topic, it is awful that the name of the backing variable includes
all of the names of the individual bindings, concatenated. That can easily
produce humongous symbol names, and interacts unusually poorly with (UB)
macro-expansion. If anyone wants to go talk to the Itanium ABI folks and get
everyone to switch to a simple "mangling number" scheme like we have already
built for lambda closure types, that would be awesome. Notice that you already
need a "mangling number" scheme *on top* of the current design, because of
https://godbolt.org/z/cYqxzxfxe — so I'm just proposing to make the scheme
simpler, if the Itanium ABI folks are willing to change it.)

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

* [Bug c++/108257] Incorrect (non-unique) mangling of structured binding's backing variable
  2022-12-31 16:01 [Bug c++/108257] New: Incorrect (non-unique) mangling of structured binding's backing variable arthur.j.odwyer at gmail dot com
@ 2022-12-31 20:06 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-31 20:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108257

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-12-31

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2022-12-31 20:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-31 16:01 [Bug c++/108257] New: Incorrect (non-unique) mangling of structured binding's backing variable arthur.j.odwyer at gmail dot com
2022-12-31 20:06 ` [Bug c++/108257] " 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).