Skip to content

Commit b3ceb5d

Browse files
authored
Merge pull request swiftlang#36626 from eeckstein/main
AccessSummaryAnalysis: relax the verification of expected no-escape partial_apply uses
2 parents a2b8292 + 479517f commit b3ceb5d

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

lib/SILOptimizer/Analysis/AccessSummaryAnalysis.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,32 +187,15 @@ static bool hasExpectedUsesOfNoEscapePartialApply(Operand *partialApplyUse) {
187187
return partialApplyUse->getOperandNumber() ==
188188
CopyBlockWithoutEscapingInst::Closure;
189189

190-
// A copy_value that is only used by the store to a block storage is fine.
191-
// It is part of the pattern we emit for verifying that a noescape closure
192-
// passed to objc has not escaped.
193-
// %4 = convert_escape_to_noescape [not_guaranteed] %3 :
194-
// $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
195-
// %5 = function_ref @withoutEscapingThunk
196-
// %6 = partial_apply [callee_guaranteed] %5(%4) :
197-
// $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
198-
// %7 = mark_dependence %6 : $@callee_guaranteed () -> () on %4 :
199-
// $@noescape @callee_guaranteed () -> ()
200-
// %8 = copy_value %7 : $@callee_guaranteed () -> ()
201-
// %9 = alloc_stack $@block_storage @callee_guaranteed () -> ()
202-
// %10 = project_block_storage %9 :
203-
// $*@block_storage @callee_guaranteed () -> ()
204-
// store %8 to [init] %10 : $*@callee_guaranteed () -> ()
205-
// %13 = init_block_storage_header %9 :
206-
// $*@block_storage @callee_guaranteed () -> (),
207-
// invoke %12
208-
// %14 = copy_block_without_escaping %13 : $() -> () withoutEscaping %7
209190
case SILInstructionKind::CopyValueInst:
210-
return isa<StoreInst>(getSingleNonDebugUser(cast<CopyValueInst>(user)));
191+
return llvm::all_of(cast<CopyValueInst>(user)->getUses(),
192+
hasExpectedUsesOfNoEscapePartialApply);
211193

212194
// End borrow is always ok.
213195
case SILInstructionKind::EndBorrowInst:
214196
return true;
215197

198+
case SILInstructionKind::IsEscapingClosureInst:
216199
case SILInstructionKind::StoreInst:
217200
case SILInstructionKind::DestroyValueInst:
218201
// @block_storage is passed by storing it to the stack. We know this is

test/SILOptimizer/exclusivity_static_diagnostics.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,18 @@ struct TestConflictInCoroutineClosureArg {
677677
// expected-note@-2 {{conflicting access is here}}
678678
}
679679
}
680+
681+
// Check that AccessSummaryAnalysis does not crash with this:
682+
struct TestStruct {
683+
var x = 7
684+
mutating func b() {
685+
func c() {}
686+
func d() {
687+
x // expected-warning {{property is accessed but result is unused}}
688+
}
689+
withoutActuallyEscaping(c) { e in
690+
withoutActuallyEscaping(d) { e in
691+
}
692+
}
693+
}
694+
}

0 commit comments

Comments
 (0)