[clang] [clang] Limit lifetimes of temporaries to the full expression (PR #170517)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 3 14:08:03 PST 2025
================
@@ -4947,7 +4948,23 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
return;
}
- args.add(EmitAnyExprToTemp(E), type);
+ AggValueSlot ArgSlot = AggValueSlot::ignored();
+ // If the callee returns a reference, skip this stack saving optimization;
----------------
efriedma-quic wrote:
There isn't any logic here that checks whether the callee returns a reference. And such a check wouldn't be useful, anyway; we can't catch all the ways a user could stash away a pointer.
I think the correct explanation is something like this:
```
// For arguments with aggregate type, create an alloca to store
// the value. If the argument's type has a destructor, that destructor
// will run at the end of the full-expression; emit matching lifetime
// markers.
//
// FIXME: For types which don't have a destructor, consider using a
// narrower lifetime bound.
```
And then #170518 implements the FIXME.
https://github.com/llvm/llvm-project/pull/170517
More information about the cfe-commits
mailing list