Skip to content

Commit 7bef317

Browse files
authored
Fix a crash in DeadArgmentTransform (#35486)
When there are no non-type dead args, DeadArgumentTransform should not specialize the function. While marking dead type args as not dead, make sure we go over all the args. If not, a dead type arg will be attempted to be deleted later on in FunctionSignatureTransform::DeadArgumentFinalizeOptimizedFunction.
1 parent e27578b commit 7bef317

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/SILOptimizer/FunctionSignatureTransforms/DeadArgumentTransform.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ bool FunctionSignatureTransform::DeadArgumentAnalyzeParameters() {
7070
for (auto &AD : TransformDescriptor.ArgumentDescList) {
7171
if (AD.IsEntirelyDead) {
7272
AD.IsEntirelyDead = false;
73-
break;
7473
}
7574
}
7675
TransformDescriptor.shouldModifySelfArgument =
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-sil-opt -sil-inline-generics -enable-sil-verify-all -inline -function-signature-opts -sil-fso-optimize-if-not-called %s | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
public protocol View {
9+
}
10+
11+
class DynamicStorage {
12+
}
13+
14+
final class ItemStorage<V> : DynamicStorage where V : View {
15+
}
16+
17+
extension View {
18+
func dynamicStorage() -> DynamicStorage
19+
}
20+
21+
sil @ItemStorage_init : $@convention(method) <V where V : View> (@in V, @owned ItemStorage<V>) -> @owned ItemStorage<V>
22+
23+
// Test to check we don't attempt to specialize when we have only dead type args
24+
// Tests there is no crash in DeadArgTransform trying to erase a type arg with debug uses
25+
26+
// CHECK-LABEL: sil @ItemStorage_alloc_init :
27+
// CHECK-LABEL: } // end sil function 'ItemStorage_alloc_init'
28+
sil @ItemStorage_alloc_init : $@convention(method) <V where V : View> (@in V, @thick ItemStorage<V>.Type, @thick ItemStorage<V>.Type) -> @owned ItemStorage<V> {
29+
bb0(%0 : $*V, %1 : $@thick ItemStorage<V>.Type, %2 : $@thick ItemStorage<V>.Type):
30+
%4 = alloc_ref $ItemStorage<V>
31+
%5 = function_ref @ItemStorage_init : $@convention(method) <τ_0_0 where τ_0_0 : View> (@in τ_0_0, @owned ItemStorage<τ_0_0>) -> @owned ItemStorage<τ_0_0>
32+
%6 = apply %5<V>(%0, %4) : $@convention(method) <τ_0_0 where τ_0_0 : View> (@in τ_0_0, @owned ItemStorage<τ_0_0>) -> @owned ItemStorage<τ_0_0>
33+
return %6 : $ItemStorage<V>
34+
}
35+

0 commit comments

Comments
 (0)