mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #79502 from gottesmm/pr-0157e2d0f6c260a7cd233938fd987b1ada6a30da
[rbi] Fix a thinko where while finding closure uses, I was not checking if functions had a body when looking for arguments.
This commit is contained in:
@@ -238,7 +238,7 @@ findClosureUse(Operand *initialOperand) {
|
||||
return {};
|
||||
|
||||
auto *f = as.getCalleeFunction();
|
||||
if (!f)
|
||||
if (!f || f->empty())
|
||||
return {};
|
||||
|
||||
unsigned argumentIndex = as.getCalleeArgIndex(*initialOperand);
|
||||
@@ -280,7 +280,7 @@ findClosureUse(Operand *initialOperand) {
|
||||
// See if we have a callee function. In such a case, find our operand in the
|
||||
// callee and visit its uses.
|
||||
if (auto as = dyn_cast<PartialApplyInst>(op->getUser())) {
|
||||
if (auto *f = as->getCalleeFunction()) {
|
||||
if (auto *f = as->getCalleeFunction(); f && !f->empty()) {
|
||||
auto *fArg = f->getArgument(ApplySite(as).getCalleeArgIndex(*op));
|
||||
for (auto *use : fArg->getUses()) {
|
||||
if (visitedOperand.insert(use).second)
|
||||
@@ -294,7 +294,7 @@ findClosureUse(Operand *initialOperand) {
|
||||
// immediately invoked. In such a case, we can emit a better diagnostic in
|
||||
// the called closure.
|
||||
if (auto fas = FullApplySite::isa(op->getUser())) {
|
||||
if (auto *f = fas.getCalleeFunction()) {
|
||||
if (auto *f = fas.getCalleeFunction(); f && !f->empty()) {
|
||||
auto *fArg = cast<SILFunctionArgument>(
|
||||
f->getArgument(fas.getCalleeArgIndex(*op)));
|
||||
if (fArg->isClosureCapture()) {
|
||||
|
||||
@@ -1933,3 +1933,14 @@ func testIndirectAndDirectSendingResultsWithGlobalActor() async {
|
||||
_ = ns2
|
||||
}
|
||||
}
|
||||
|
||||
// We used to not check if bodies were not empty when emitting the error for
|
||||
// using result in the throwing task group. Make sure we do not crash.
|
||||
func testFunctionIsNotEmpty(input: SendableKlass) async throws {
|
||||
var result: [SendableKlass] = []
|
||||
try await withThrowingTaskGroup(of: Void.self) { taskGroup in // expected-warning {{no calls to throwing functions occur within 'try' expression}}
|
||||
taskGroup.addTask { // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
|
||||
result.append(input) // expected-tns-note {{closure captures reference to mutable var 'result' which is accessible to code in the current task}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user