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
This commit is contained in:
Andrew Trick
2024-01-25 22:09:45 -08:00
parent 0c4efe4b73
commit 2b70d2dad8

View File

@@ -124,7 +124,7 @@ public:
// If we have an inout parameter that isn't ever actually written to, return
// false.
if (!arg->isIndirectResult() &&
arg->getKnownParameterInfo().isIndirectMutating()) {
arg->getArgumentConvention().isExclusiveIndirectParameter()) {
auto wellBehavedWrites = ctx.addressToExhaustiveWriteListCache.get(arg);
if (!wellBehavedWrites.has_value()) {
return answer(true);