Description
C23 6.2.4 Storage durations of objects:
5 An object whose identifier is declared with no linkage and without the storage-class specifier static
has automatic storage duration, as do some compound literals. The result of attempting to indirectly
access an object with automatic storage duration from a thread other than the one with which the
object is associated is implementation-defined.
6 For such an object that does not have a variable length array type, its lifetime extends from entry
into the block with which it is associated until execution of that block ends in any way
as noted here: https://reviews.llvm.org/D74094#4647616
example:
struct foo { long long x, y, z; int w; };
void bar (struct foo);
void baz (void) {
{
bar((struct foo){
.x = 42,
.y = 25,
.z = 77,
});
}
{
bar((struct foo){
.x = 42,
.y = 25,
.z = 77,
});
}
}
we should emit lifetime markers for those alloca
s as we should be able to reuse their stack slots. That should help us reduce stack usage for C codebases. cc @rjmccall @ilovepi
It should be noted that C23 added support for static storage duration for those literals (add the static
keyword before struct
in the literal); AFAICT clang doesn't support those yet, but care should be taken not to emit any lifetime markers for static storage variables (this might not be a concern, since those shouldn't have a corresponding alloca I think).