Skip to content

Fix infinite loop in the new hasPointerEscape(SILValue) api #64708

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 1 commit into from
Mar 29, 2023
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
2 changes: 1 addition & 1 deletion lib/SIL/Utils/OwnershipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool swift::hasPointerEscape(SILValue original) {
return true;
});
}
while (auto value = worklist.popAndForget()) {
while (auto value = worklist.pop()) {
for (auto use : value->getUses()) {
switch (use->getOperandOwnership()) {
case OperandOwnership::PointerEscape:
Expand Down
29 changes: 29 additions & 0 deletions test/SILOptimizer/ownership-utils-unit.sil
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import Builtin

class C {}

enum FakeOptional<T> {
case none
case some(T)
}

sil @getOwned : $@convention(thin) () -> (@owned C)

sil @borrow : $@convention(thin) (@guaranteed C) -> ()
Expand Down Expand Up @@ -42,3 +47,27 @@ exit(%instance : @owned $C):
%retval = tuple ()
return %retval : $()
}

sil [ossa] @test_loop_phi : $@convention(thin) () -> () {
entry:
%instance_1 = enum $FakeOptional<C>, #FakeOptional.none!enumelt
br loop_entry(%instance_1 : $FakeOptional<C>)

loop_entry(%18 : @owned $FakeOptional<C>):
test_specification "has-pointer-escape @block.argument"
br loop_body

loop_body:
cond_br undef, loop_back, loop_exit

loop_back:
br loop_entry(%18 : $FakeOptional<C>)

loop_exit:
destroy_value %18 : $FakeOptional<C>
br exit

exit:
%retval = tuple ()
return %retval : $()
}