Skip to content

Commit 000eaed

Browse files
committed
SIL: look through end_init_let_ref instructions when checking for isLexical
`end_init_let_ref` instructions are inserted in class initializers after all fields are initialized. It's important to look through such instructions when checking the `isLexical` property of a value. Fixes a mis-compile due to shrinking a lexical liferange of a class. Part of rdar://140229560
1 parent e4887c7 commit 000eaed

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/SIL/IR/SILValue.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ bool ValueBase::isLexical() const {
153153
return bbi->isLexical();
154154
if (auto *mvi = dyn_cast<MoveValueInst>(this))
155155
return mvi->isLexical();
156+
157+
// TODO: This is only a workaround. Optimizations should look through such instructions to
158+
// get the isLexical state, instead of doing it here.
159+
// rdar://143577158
160+
if (auto *eilr = dyn_cast<EndInitLetRefInst>(this))
161+
return eilr->getOperand()->isLexical();
162+
156163
return false;
157164
}
158165

test/SILOptimizer/copy_propagation.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,3 +1071,24 @@ sil [ossa] @dontShortenDeadMoveOnlyLifetime : $@convention(thin) () -> () {
10711071
%retval = tuple ()
10721072
return %retval : $()
10731073
}
1074+
1075+
// CHECK-LABEL: sil [ossa] @look_through_end_init_let_ref :
1076+
// CHECK: [[E:%.*]] = end_init_let_ref
1077+
// CHECK: [[D:%.*]] = function_ref @dummy
1078+
// CHECK: apply [[D]]
1079+
// CHECK: destroy_value [[E]]
1080+
// CHECK-LABEL: } // end sil function 'look_through_end_init_let_ref'
1081+
sil [ossa] @look_through_end_init_let_ref : $@convention(thin) () -> () {
1082+
bb0:
1083+
%0 = alloc_ref $C
1084+
%1 = move_value [lexical] %0
1085+
%2 = end_init_let_ref %1
1086+
%4 = function_ref @takeGuaranteedC : $@convention(thin) (@guaranteed C) -> ()
1087+
apply %4(%2) : $@convention(thin) (@guaranteed C) -> ()
1088+
%6 = function_ref @dummy : $@convention(thin) () -> ()
1089+
apply %6() : $@convention(thin) () -> ()
1090+
destroy_value %2
1091+
%3 = tuple ()
1092+
return %3
1093+
}
1094+

0 commit comments

Comments
 (0)