On 2024-02-21 15:33, Nathaniel Shead wrote:
On Wed, Feb 21, 2024 at 03:02:55PM +0400, Daniil Frolov wrote:
Hi.
Following the recent introduction of more detailed CLOBBER types in
GCC, a
minor
inconsistency has been identified in the description of
CLOBBER_OBJECT_BEGIN:
/* Beginning of object lifetime, e.g. C++ constructor. */
CLOBBER_OBJECT_BEGIN
This comment appears somewhat contradictory, as according to the C++
standard,
an object's lifetime commences upon completion of its initialization:
> The lifetime of an object of type T begins when:
> -- storage with the proper alignment and size for type T is obtained,
> and
> -- its initialization (if any) is complete (including vacuous
> initialization)
etc.
However, GCC emits CLOBBERs of this type at the beginning of a
constructor.
And similarly for CLOBBER_OBJECT_END; by the standard an object ends
its
lifetime at the start of the destructor, while we emit this at the end
of the destructor call.
Oh, thanks. I forgot about this one.
However, both placements are useful. At least for constexpr, the
current
meaning of CLOBBER_OBJECT_END is important to know when we can still
access members of a class undergoing construction or destruction (see
[class.cdtor] p1) since this isn't directly tied to the elifetime of
the
containing object itself.
Yes, I agree this behavior is useful. I realized the same thing when I
worked
with the patch for emitting Valgrind annotation: setting memory as
undefined
after constructor is done (if CLOBBER_OBJECT_START would be placed
there) would
provoke FP.
But I'm still working for GCC 15 on correctly handling "partially
constructed" objects in constexpr (e.g. PR109518), and having a version
of CLOBBER_OBJECT_BEGIN at the /end/ of the constructor to signal this
might be useful as due to splitting of non-constant initialisers this
is
otherwise a little awkward to determine from the IR currently.
Does anybody have any ideas how to make this description more precise?
It'd
be
better to clearly define what an object's lifetime is at the GIMPLE
IMHO.
So, given the above, I think CLOBBER_OBJECT_BEGIN is still a pretty
good
name (though maybe not perfect?), but maybe the comment should say
something like "Beginning of object construction"? Or otherwise mention
that this is the start of the lifetime of either the object or its
first
subobject.
Maybe I've not clearly understood what does 'object construction' mean,
but I want
to mention that C++ constructor is not the only point when lifetime of
an object
begins. There are few exceptions for unions and for std::allocator (in
C++) so it
looks a bit hard for me to generalize.
---
With best regards,
Daniil
Yours,
Nathaniel.
---
With best regards,
Daniil