Skip to content

Commit 2f81e4e

Browse files
committed
CopyForwarding: We need to check whether an argument is a function argument before checking its convention
1 parent fd566d9 commit 2f81e4e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/SILOptimizer/Transforms/CopyForwarding.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static llvm::cl::opt<bool> EnableDestroyHoisting("enable-destroyhoisting",
9393
/// (2) A local alloc_stack variable.
9494
static bool isIdentifiedSourceValue(SILValue Def) {
9595
if (SILArgument *Arg = dyn_cast<SILArgument>(Def)) {
96+
if (!Arg->isFunctionArg())
97+
return false;
9698
// Check that the argument is passed as an in type. This means there are
9799
// no aliases accessible within this function scope.
98100
ParameterConvention Conv = Arg->getParameterInfo().getConvention();

test/SILOptimizer/copyforward.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ bb0(%0 : $*T):
7171
return %r1 : $()
7272
}
7373

74+
//CHECK-LABEL: dont_assert_on_basic_block_arg
75+
//CHECK: return
76+
sil hidden @dont_assert_on_basic_block_arg : $@convention(thin) <T> (@in T) -> () {
77+
bb0(%0 : $*T):
78+
debug_value_addr %0 : $*T
79+
br bb1(%0: $*T)
80+
81+
bb1(%1 : $*T):
82+
%l1 = alloc_stack $T
83+
copy_addr %1 to [initialization] %l1 : $*T
84+
%f1 = function_ref @f_in : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
85+
%c1 = apply %f1<T>(%l1) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
86+
debug_value_addr %l1 : $*T
87+
dealloc_stack %l1 : $*T
88+
debug_value_addr %0 : $*T
89+
destroy_addr %0 : $*T
90+
%r1 = tuple ()
91+
return %r1 : $()
92+
}
93+
7494
//CHECK-LABEL: forward_noinit
7595
//CHECK-NOT: copy_addr
7696
//CHECK: destroy_addr

0 commit comments

Comments
 (0)