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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

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

commit r16-3944-gc1e1691b95e65c53a2b9c25de70c56655215b905
Author: Jakub Jelinek <[email protected]>
Date:   Thu Sep 18 07:44:54 2025 +0200

    libstdc++: Implement C++23 P2590R2 - Explicit lifetime management
[PR106658]

    As I can't think of how the middle-end would treat
    __builtin_start_lifetime_as other than a blackbox and probably would
    need to be implemented as such inline asm in RTL, this patch
    just implements it using inline asm in the library.
    If not anything else, it can serve as fallback before we and/or clang
    get some builtin for it.

    Right now the inline asms pretend (potential) read from and write to the
whole
    memory region and make optimizers forget where the return value points to.
    If the optimizers don't know where it points to, I think that should be
    good enough, but I'm a little bit afraid of possibly future optimizations
    trying to optimize
      q->c = 1;
      q->d = 2;
      auto p = std::start_lifetime_as<S>(q);
      if (p == reinterpret_cast<decltype (p)>(q))
        return p->a + p->b;
    that because of the guarding condition or perhaps assertion we could
    simply use the q pointer in MEM_REFs with S type and be surprised by TBAA.
    Though if it is a must-alias case, then we should be fine as well.
    Though guess that would be the same case with a builtin.

    2025-09-18  Jakub Jelinek  <[email protected]>

            PR c++/106658
            * include/bits/version.def: Implement C++23 P2590R2 - Explicit
            lifetime management.
            (start_lifetime_as): New.
            * include/bits/version.h: Regenerate.
            * include/std/memory (std::start_lifetime_as,
            std::start_lifetime_as_array): New function templates.
            * src/c++23/std.cc.in (std::start_lifetime_as,
            std::start_lifetime_as_array): Export.
            * testsuite/std/memory/start_lifetime_as/start_lifetime_as.cc: New
test.

Reply via email to