Bug 106658 - [C++23] P2590 - Explicit lifetime management
Summary: [C++23] P2590 - Explicit lifetime management
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: c++23-core
  Show dependency treegraph
 
Reported: 2022-08-16 17:33 UTC by Marek Polacek
Modified: 2024-08-14 15:36 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-12-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2022-08-16 17:33:30 UTC
See <https://wg21.link/p2590>.
Comment 1 Richard Biener 2022-08-17 10:18:32 UTC
1.1 can be done without any code but 1.2 makes std::start_lifetime_at <T> (p)
retain the memory bit representation as initial value of the object?  The
paper mentions std::launder (ick), but I'm not sure how this is implementable
at all if not sufficiently restricted.
Comment 2 Richard Biener 2022-08-17 11:09:55 UTC
See for example PR101641 where even existing cases are currently impossible to get right.  So the only way to make std::start_lifetime_at <T> is to somehow
emit a hard memory barrier for the compiler _and_ make sure the underlying
storage is address-taken.  Note this barrier has to prevail in RTL as well
(I think std::launder is broken in this regard).
Comment 3 Andrew Pinski 2022-12-09 15:27:58 UTC
.
Comment 4 Jakub Jelinek 2024-08-14 15:36:15 UTC
Do we really need to do anything at all (except defining the new stuff in a header), or possibly using __builtin_launder in it?
I mean, my understanding of the start lifetime as something is as if with -flifetime-dse=1 there was a call to a constructor which just did nothing at all (like e.g. the struct X { int a, b; }; constructor does).  And when we inline such an constructor, there is no CLOBBER and no code at all, so in the end nothing.
__builtin_launder is just an optimization barrier (and indeed it can look like the address escapes).

I think PR101641 is just bad example, we do allow type punning through union, but only if we can see it being done.  The testcase is trying to change active union member through just a store through a pointer to union member, that is not what we support I believe.