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.

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 lifetime of the
containing object itself.

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.

Yours,
Nathaniel.

> ---
> With best regards,
> Daniil

Reply via email to