Skip to content

Commit 2da0f60

Browse files
committed
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.
1 parent 000e630 commit 2da0f60

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/SILOptimizer/Transforms/CopyForwarding.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,11 @@ static bool canNRVO(CopyAddrInst *CopyInst) {
10671067
// optimization will early-initialize the copy dest, so we can't allow aliases
10681068
// to be accessed between the initialization and the return.
10691069
auto OutArg = dyn_cast<SILArgument>(CopyInst->getDest());
1070-
if (!OutArg || !OutArg->getParameterInfo().isIndirect())
1070+
if (!OutArg)
1071+
return false;
1072+
1073+
auto ArgConv = OutArg->getParameterInfo().getConvention();
1074+
if (ArgConv != ParameterConvention::Indirect_Out)
10711075
return false;
10721076

10731077
SILBasicBlock *BB = CopyInst->getParent();

0 commit comments

Comments
 (0)