public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111069] New: Mangling of static structured bindings
@ 2023-08-18 18:47 jakub at gcc dot gnu.org
  2023-08-18 18:50 ` [Bug c++/111069] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-18 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111069
           Summary: Mangling of static structured bindings
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

void
corge ()
{
  static int a[2];
  static auto [i, j] = a;
  static auto [k, l] = a;
  {
    static auto [i, j] = a;
    static auto [k, l] = a;
  }
  {
    static auto [i, j] = a;
    static auto [k, l] = a;
  }
}

fails to assemble with -std=c++20, we use
_ZNDC1i1jEE and _ZNDC1k1lEE as names of the local variables multiple times
(+ _ZGVZ5corgevE11_ZNDC1i1jEE and _ZGVZ5corgevE11_ZNDC1k1lEE for guards which
are emitted each just once but prevent the initialization of the second and
third case).
clang++ uses _ZZ5corgevEDC1i1jE, _ZZ5corgevEDC1k1lE_0, _ZZ5corgevEDC1i1jE_1,
_ZZ5corgevEDC1k1lE_2 etc. and corresponding guard vars.
Now, I guess for local vars it is up to us to name those as we want as long as
there is no clash, with
inline void
freddy ()
{
  static int a[2];
  static auto [i, j] = a;
  static auto [k, l] = a;
  {
    static auto [i, j] = a;
    static auto [k, l] = a;
  }
  {
    static auto [i, j] = a;
    static auto [k, l] = a;
  }
}
void (*p)() = &freddy;
it is an ABI issue.

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
@ 2023-08-18 18:50 ` jakub at gcc dot gnu.org
  2023-08-18 18:51 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-18 18:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Apparently my fault as I've done r10-720-gb7f0df71a9de2354fcb7 which enabled
it,
but am not really sure what is the correct mangling.

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
  2023-08-18 18:50 ` [Bug c++/111069] " jakub at gcc dot gnu.org
@ 2023-08-18 18:51 ` pinskia at gcc dot gnu.org
  2023-08-18 19:02 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-18 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=108257

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect this is a dup of bug 108257 .

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
  2023-08-18 18:50 ` [Bug c++/111069] " jakub at gcc dot gnu.org
  2023-08-18 18:51 ` pinskia at gcc dot gnu.org
@ 2023-08-18 19:02 ` jakub at gcc dot gnu.org
  2023-08-18 19:08 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-18 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yes, though this PR has more info.

grep 1[ik]1[jl] pr111069-2.s | grep :
_ZZ6freddyvEDC1i1jE:
_ZGVZ6freddyvEDC1i1jE:
_ZZ6freddyvEDC1k1lE:
_ZGVZ6freddyvEDC1k1lE:
_ZZ6freddyvEDC1i1jE_0:
_ZGVZ6freddyvEDC1i1jE_0:
_ZZ6freddyvEDC1k1lE_0:
_ZGVZ6freddyvEDC1k1lE_0:
_ZZ6freddyvEDC1i1jE_1:
_ZGVZ6freddyvEDC1i1jE_1:
_ZZ6freddyvEDC1k1lE_1:
_ZGVZ6freddyvEDC1k1lE_1:
shows that for inline functions I think clang++ mangling is right.

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-08-18 19:02 ` jakub at gcc dot gnu.org
@ 2023-08-18 19:08 ` jakub at gcc dot gnu.org
  2023-08-19 10:12 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-18 19:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-08-18

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-08-18 19:08 ` jakub at gcc dot gnu.org
@ 2023-08-19 10:12 ` jakub at gcc dot gnu.org
  2023-08-21  9:20 ` jakub at gcc dot gnu.org
  2023-09-01 13:15 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-19 10:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 55763
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55763&action=edit
gcc14-pr111069-wip.patch

WIP patch.  Seems to get the basics right, but mangling of guard vars (_ZGV*)
and life-extended vars (_ZGR*) needs work.  The latter will be hard, because
adding a full demangler to mangle.cc so that it handles arbitrary local names
would be undesirable.

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-08-19 10:12 ` jakub at gcc dot gnu.org
@ 2023-08-21  9:20 ` jakub at gcc dot gnu.org
  2023-09-01 13:15 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-21  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #55763|0                           |1
        is obsolete|                            |

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 55769
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55769&action=edit
gcc14-pr111069.patch

Full untested patch.

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

* [Bug c++/111069] Mangling of static structured bindings
  2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-08-21  9:20 ` jakub at gcc dot gnu.org
@ 2023-09-01 13:15 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-01 13:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:cd37325b8d500bf4021692620686572d5ffb0868

commit r14-3624-gcd37325b8d500bf4021692620686572d5ffb0868
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Sep 1 15:07:48 2023 +0200

    c++: Fix up mangling of function/block scope static structured bindings
[PR111069]

    As can be seen on the testcase, we weren't correctly mangling
    static/thread_local structured bindings (C++20 feature) at function/block
    scope.  The following patch fixes that by using what write_local_name
    does for those cases (note, structured binding mandling doesn't use the
    standard path because it needs to pass a list of all the identifiers in
    the structured binding to the mangling).  In addition to that it fixes
    mangling of various helpers which use write_guarded_name (_ZGV*, _ZTH*,
    _ZTW*) and kills find_decomp_unqualified_name which for the local names
    would be too hard to implement and uses write_guarded_name for structured
    binding related _ZGR* names as well.

    All the mangled names on the first testcase match now clang++ and my
    expectations.
    Because the old mangled names were plain wrong (they mangled the same as
    structured binding at global scope and resulted in assembly errors if there
    was more than one static structured binding with the same identifiers in
    the same (or another) function, I think we don't need to play with another
    mangling ABI level which turns on/off the old broken way.

    In addition to that the patch starts to emit abi-tags into the
mangle_decomp
    produced names when needed and emits a -Wabi warning for that as well.
    To make that work, I had to move cp_maybe_mangle_decomp calls from before
    cp_finish_decl into a middle of cp_finish_decl after type is deduced and
    maybe_commonize_var (which also had to be changed not to ignore structured
    bindings) is called but before anything might need a mangled name for the
    decl, so a new cp_decomp structure is passed to cp_finish_decl; various
    other structured binding related functions have been changed to pass
    pointer to that around instead of passing a tree and unsigned int
separately.

    On decomp9.C, there is a
    _ZZ3barI1TB3quxEivEDC1o1pEB3qux
    (g++) vs.
    _ZZ3barI1TB3quxEivEDC1o1pE
    (clang++) mangling difference, but that seems to be a clang++ bug and
happens
    also with normal static block vars, doesn't need structured bindings.

    2023-09-01  Jakub Jelinek  <jakub@redhat.com>

            PR c++/111069
    gcc/
            * common.opt (fabi-version=): Document version 19.
            * doc/invoke.texi (-fabi-version=): Likewise.
    gcc/c-family/
            * c-opts.cc (c_common_post_options): Change latest_abi_version to
19.
    gcc/cp/
            * cp-tree.h (determine_local_discriminator): Add NAME argument with
            NULL_TREE default.
            (struct cp_decomp): New type.
            (cp_finish_decl): Add DECOMP argument defaulted to nullptr.
            (cp_maybe_mangle_decomp): Remove declaration.
            (cp_finish_decomp): Add cp_decomp * argument, remove tree and
unsigned
            args.
            (cp_convert_range_for): Likewise.
            * decl.cc (determine_local_discriminator): Add NAME argument, use
it
            if non-NULL, otherwise compute it the old way.
            (maybe_commonize_var): Don't return early for structured bindings.
            (cp_finish_decl): Add DECOMP argument, if non-NULL, call
            cp_maybe_mangle_decomp.
            (cp_maybe_mangle_decomp): Make it static with a forward
declaration.
            Call determine_local_discriminator.  Replace FIRST and COUNT
arguments
            with DECOMP argument.
            (cp_finish_decomp): Replace FIRST and COUNT arguments with DECOMP
            argument.
            * mangle.cc (find_decomp_unqualified_name): Remove.
            (write_unqualified_name): Don't call find_decomp_unqualified_name.
            (mangle_decomp): Handle mangling of static function/block scope
            structured bindings.  Don't call decl_mangling_context twice.  Call
            check_abi_tags, call write_abi_tags for abi version >= 19 and emit
            -Wabi warnings if needed.
            (write_guarded_var_name): Handle structured bindings.
            (mangle_ref_init_variable): Use write_guarded_var_name.
            * parser.cc (cp_parser_range_for): Adjust
do_range_for_auto_deduction
            and cp_convert_range_for callers.
            (do_range_for_auto_deduction): Replace DECOMP_FIRST_NAME and
            DECOMP_CNT arguments with DECOMP.  Adjust cp_finish_decomp caller.
            (cp_convert_range_for): Replace DECOMP_FIRST_NAME and
            DECOMP_CNT arguments with DECOMP.  Don't call
cp_maybe_mangle_decomp,
            adjust cp_finish_decl and cp_finish_decomp callers.
            (cp_parser_decomposition_declaration): Don't call
            cp_maybe_mangle_decomp, adjust cp_finish_decl and cp_finish_decomp
            callers.
            (cp_convert_omp_range_for): Adjust do_range_for_auto_deduction
            and cp_finish_decomp callers.
            (cp_finish_omp_range_for): Don't call cp_maybe_mangle_decomp,
            adjust cp_finish_decl and cp_finish_decomp callers.
            * pt.cc (tsubst_omp_for_iterator): Adjust tsubst_decomp_names
            caller.
            (tsubst_decomp_names): Replace FIRST and CNT arguments with DECOMP.
            (tsubst_expr): Don't call cp_maybe_mangle_decomp, adjust
            tsubst_decomp_names, cp_finish_decl, cp_finish_decomp and
            cp_convert_range_for callers.
    gcc/testsuite/
            * g++.dg/cpp2a/decomp8.C: New test.
            * g++.dg/cpp2a/decomp9.C: New test.
            * g++.dg/abi/macro0.C: Expect __GXX_ABI_VERSION 1019 rather than
            1018.

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

end of thread, other threads:[~2023-09-01 13:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18 18:47 [Bug c++/111069] New: Mangling of static structured bindings jakub at gcc dot gnu.org
2023-08-18 18:50 ` [Bug c++/111069] " jakub at gcc dot gnu.org
2023-08-18 18:51 ` pinskia at gcc dot gnu.org
2023-08-18 19:02 ` jakub at gcc dot gnu.org
2023-08-18 19:08 ` jakub at gcc dot gnu.org
2023-08-19 10:12 ` jakub at gcc dot gnu.org
2023-08-21  9:20 ` jakub at gcc dot gnu.org
2023-09-01 13:15 ` cvs-commit 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).