mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Explicitly restrict NRVO optimization to "out" args.
Don't allow this optimization to kick in for "inout" args. The optimization may expose local writes to any aliases of the argument. I can't prove that is memory safe. Erik pointed out this case.
This commit is contained in:
@@ -1067,7 +1067,11 @@ static bool canNRVO(CopyAddrInst *CopyInst) {
|
||||
// optimization will early-initialize the copy dest, so we can't allow aliases
|
||||
// to be accessed between the initialization and the return.
|
||||
auto OutArg = dyn_cast<SILArgument>(CopyInst->getDest());
|
||||
if (!OutArg || !OutArg->getParameterInfo().isIndirect())
|
||||
if (!OutArg)
|
||||
return false;
|
||||
|
||||
auto ArgConv = OutArg->getParameterInfo().getConvention();
|
||||
if (ArgConv != ParameterConvention::Indirect_Out)
|
||||
return false;
|
||||
|
||||
SILBasicBlock *BB = CopyInst->getParent();
|
||||
|
||||
Reference in New Issue
Block a user