Skip to content

Commit 3493142

Browse files
committed
EscapeAnalysis: handle SILUndef values
fixes a crash rdar://problem/50279857
1 parent 5a27eb4 commit 3493142

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,11 @@ static bool mayContainReference(SILType Ty, const SILFunction &F) {
10701070

10711071
bool EscapeAnalysis::isPointer(ValueBase *V) {
10721072
auto *F = V->getFunction();
1073+
1074+
// The function can be null, e.g. if V is an undef.
1075+
if (!F)
1076+
return false;
1077+
10731078
SILType Ty = V->getType();
10741079
auto Iter = isPointerCache.find(Ty);
10751080
if (Iter != isPointerCache.end())

test/SILOptimizer/escape_analysis.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ struct FourFields {
7474
let d : Y
7575
}
7676

77+
sil @take_indirect_tuple : $@convention(method) (@in (Int, ())) -> ()
78+
79+
// CHECK-LABEL: CG of handle_undef
80+
// CHECK: Val %2 Esc: G, Succ: (%2.1)
81+
// CHECK: Con %2.1 Esc: G, Succ:
82+
// CHECK: End
83+
sil @handle_undef : $@convention(thin) (Int) -> () {
84+
bb0(%0 : $Int):
85+
%1 = tuple $(Int, ()) (%0, undef)
86+
%5 = alloc_stack $(Int, ())
87+
store %1 to %5 : $*(Int, ())
88+
%7 = function_ref @take_indirect_tuple : $@convention(method) (@in (Int, ())) -> ()
89+
%8 = apply %7(%5) : $@convention(method) (@in (Int, ())) -> ()
90+
dealloc_stack %5 : $*(Int, ())
91+
%10 = tuple ()
92+
return %10 : $()
93+
}
94+
7795
// Sanity check with a simple function.
7896

7997
// CHECK-LABEL: CG of test_simple

0 commit comments

Comments
 (0)