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:
Andrew Trick
2015-12-22 17:55:47 -08:00
parent 000e630b2f
commit 2da0f601d8

View File

@@ -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();