Skip to content

[region-isolation] Fix assert. #72366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Analysis/RegionAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ class PartitionOpTranslator {
}

void translateSILLookThrough(SingleValueInstruction *svi) {
assert(svi->getNumOperands() == 1);
assert(svi->getNumRealOperands() == 1);
auto srcID = tryToTrackValue(svi->getOperand(0));
auto destID = tryToTrackValue(svi);
assert(((!destID || !srcID) || destID->getID() == srcID->getID()) &&
Expand Down Expand Up @@ -2261,7 +2261,7 @@ class PartitionOpTranslator {
return;

case TranslationSemantics::LookThrough:
assert(inst->getNumOperands() == 1);
assert(inst->getNumRealOperands() == 1);
assert((isStaticallyLookThroughInst(inst) ||
isLookThroughIfResultNonSendable(inst) ||
isLookThroughIfOperandNonSendable(inst) ||
Expand Down
25 changes: 24 additions & 1 deletion test/Concurrency/transfernonsendable_instruction_matching.sil
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ case none
case some(T)
}

open class ParentClass {
}
class ChildClass : ParentClass {}

sil @copyParentClass : $@convention(thin) (@guaranteed ParentClass) -> @owned ParentClass

/////////////////
// MARK: Tests //
/////////////////
Expand Down Expand Up @@ -1485,7 +1491,7 @@ bb0:
// Now transfer %addr and use it.
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%addr) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
%f2 = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
apply %f2<NonSendableKlass>(%addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{access here could race}}
apply %f2<NonSendableKlass>(%addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{access here could race}}

dealloc_pack %pack2 : $*Pack{NonSendableKlass, repeat each T}
dealloc_pack %pack : $*Pack{NonSendableKlass, repeat each T}
Expand Down Expand Up @@ -1649,3 +1655,20 @@ bb0(%arg : $Builtin.Word):
%9999 = tuple ()
return %9999 : $()
}

sil hidden [ossa] @test_unconditional_checked_cast : $@convention(method) (@guaranteed ChildClass) -> @owned ChildClass {
bb0(%0 : @guaranteed $ChildClass):
debug_value %0 : $ChildClass, let, name "self", argno 1, implicit
%2 = copy_value %0 : $ChildClass
%3 = upcast %2 : $ChildClass to $ParentClass
%4 = function_ref @copyParentClass : $@convention(thin) (@guaranteed ParentClass) -> @owned ParentClass
%5 = apply %4(%3) : $@convention(thin) (@guaranteed ParentClass) -> @owned ParentClass
%6 = unchecked_ref_cast %5 : $ParentClass to $ChildClass
%7 = unconditional_checked_cast %6 : $ChildClass to @dynamic_self ChildClass
%8 = move_value [lexical] [var_decl] %7 : $ChildClass
debug_value %8 : $ChildClass, let, name "copy"
destroy_value %3 : $ParentClass
%11 = copy_value %8 : $ChildClass
destroy_value %8 : $ChildClass
return %11 : $ChildClass
}