Skip to content

EscapeAnalysis: handle SILUndef values #24372

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
Apr 29, 2019
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
5 changes: 5 additions & 0 deletions lib/SILOptimizer/Analysis/EscapeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,11 @@ static bool mayContainReference(SILType Ty, const SILFunction &F) {

bool EscapeAnalysis::isPointer(ValueBase *V) {
auto *F = V->getFunction();

// The function can be null, e.g. if V is an undef.
if (!F)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for this to happen for anything but undef? Maybe put in an assert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think currently not. This is the safe default (in case we add another SILValue kind in the future)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we won't know to update this code when someone adds something new. They won't be able to know to make the decision. With the assert, when someone adds the new SILValue, they get a hard warning that they may need to update this code.

return false;

SILType Ty = V->getType();
auto Iter = isPointerCache.find(Ty);
if (Iter != isPointerCache.end())
Expand Down
18 changes: 18 additions & 0 deletions test/SILOptimizer/escape_analysis.sil
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ struct FourFields {
let d : Y
}

sil @take_indirect_tuple : $@convention(method) (@in (Int, ())) -> ()

// CHECK-LABEL: CG of handle_undef
// CHECK: Val %2 Esc: G, Succ: (%2.1)
// CHECK: Con %2.1 Esc: G, Succ:
// CHECK: End
sil @handle_undef : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%1 = tuple $(Int, ()) (%0, undef)
%5 = alloc_stack $(Int, ())
store %1 to %5 : $*(Int, ())
%7 = function_ref @take_indirect_tuple : $@convention(method) (@in (Int, ())) -> ()
%8 = apply %7(%5) : $@convention(method) (@in (Int, ())) -> ()
dealloc_stack %5 : $*(Int, ())
%10 = tuple ()
return %10 : $()
}

// Sanity check with a simple function.

// CHECK-LABEL: CG of test_simple
Expand Down