Hi all,
for every stack variable, clang models the lifetime of the variable with llvm.lifetime.start and llvm.lifetime.end intrinsics.
I was a bit surprised that clang is not adding lifetime intrinsics for temporary objects that typically (except of lifetime extended temporaries) have a lifetime of the statement.
Example
In the following example, lifetime intrinsics are created for a A
but not for the temporary object created within b()
. See Compiler Explorer .
struct a {
~a();
};
a b();
int cond;
void f() {
if (cond) {
a A;
b();
}
}
Questions
- Is there a reason that no lifetime intrinsics are created for temporary objects? (a bug or a feature)
- Does clang give away optimization potential (e.g. for stack size) by not adding lifetime intrinsics for temporary objects?