Skip to content

Commit 2b70d2d

Browse files
committed
Fix SemanticARCOpts LoadCopyToBorrowOpt for ObjC closure thunk
This fixes a use-after-free miscompile. LoadCopyToBorrowOpt alias analysis was wrong in visitArgumentAccess. inout_aliasable does not give you exclusive access to an address. This resulted in removal of a retain before calling an ObjC block after converting it from a Swift closure. @_silgen_name("foreign") func foreign(block: @escaping @convention(block) () -> Void) public func doit(closure: @escaping () -> ()) { foreign { [closure] in closure() } } Fixes rdar://121268094
1 parent 0c4efe4 commit 2b70d2d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/SILOptimizer/SemanticARC/LoadCopyToLoadBorrowOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class StorageGuaranteesLoadVisitor
124124
// If we have an inout parameter that isn't ever actually written to, return
125125
// false.
126126
if (!arg->isIndirectResult() &&
127-
arg->getKnownParameterInfo().isIndirectMutating()) {
127+
arg->getArgumentConvention().isExclusiveIndirectParameter()) {
128128
auto wellBehavedWrites = ctx.addressToExhaustiveWriteListCache.get(arg);
129129
if (!wellBehavedWrites.has_value()) {
130130
return answer(true);

0 commit comments

Comments
 (0)