Skip to content

Commit f65dac9

Browse files
committed
Use addresses to represent inout/inout_aliasable when using opaque values
1 parent d43a6e1 commit f65dac9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,11 @@ static void emitCaptureArguments(SILGenFunction &SGF,
458458
// Non-escaping stored decls are captured as the address of the value.
459459
auto type = getVarTypeInCaptureContext();
460460
SILType ty = SGF.getLoweredType(type);
461-
if (SGF.SGM.M.useLoweredAddresses()) {
461+
auto argConv = SGF.F.getConventions().getSILArgumentConvention(
462+
SGF.F.begin()->getNumArguments());
463+
bool isInOut = (argConv == SILArgumentConvention::Indirect_Inout ||
464+
argConv == SILArgumentConvention::Indirect_InoutAliasable);
465+
if (isInOut || SGF.SGM.M.useLoweredAddresses()) {
462466
ty = ty.getAddressType();
463467
}
464468
SILValue arg = SGF.F.begin()->createFunctionArgument(ty, VD);

test/SILGen/opaque_values_silgen.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,11 @@ extension Array where Element == Int {
367367
}
368368
}
369369
}
370+
371+
// CHECK-LABEL: sil private [ossa] @$s20opaque_values_silgen22anon_read_only_captureyS2iFSiyXEfU_ : $@convention(thin) (@inout_aliasable Int) -> Int {
372+
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen22anon_read_only_captureyS2iFSiyXEfU_'
373+
func anon_read_only_capture(_ x: Int) -> Int {
374+
var x = x
375+
return ({ x })()
376+
}
377+

0 commit comments

Comments
 (0)