Skip to content

Commit 8996b9d

Browse files
authored
Merge pull request #31043 from eeckstein/fix-fso
FunctionSignatureOpts: fix a crash due to a missing argument declaration
2 parents 142791b + 0c3e6e2 commit 8996b9d

File tree

6 files changed

+73
-26
lines changed

6 files changed

+73
-26
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -601,31 +601,41 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
601601
if (BB->args_empty())
602602
return;
603603

604-
for (SILValue V : BB->getArguments()) {
605-
if (V->use_empty())
606-
continue;
607-
*this << "// " << Ctx.getID(V);
608-
PrintState.OS.PadToColumn(50);
609-
*this << "// user";
610-
if (std::next(V->use_begin()) != V->use_end())
611-
*this << 's';
612-
*this << ": ";
604+
for (SILArgument *arg : BB->getArguments()) {
605+
StringRef name;
606+
if (arg->getDecl() && arg->getDecl()->hasName())
607+
name = arg->getDecl()->getBaseName().userFacingName();
613608

614-
llvm::SmallVector<ID, 32> UserIDs;
615-
for (auto *Op : V->getUses())
616-
UserIDs.push_back(Ctx.getID(Op->getUser()));
609+
if (arg->use_empty() && name.empty())
610+
continue;
617611

618-
// Display the user ids sorted to give a stable use order in the
619-
// printer's output if we are asked to do so. This makes diffing large
620-
// sections of SIL significantly easier at the expense of not showing
621-
// the _TRUE_ order of the users in the use list.
622-
if (Ctx.sortSIL()) {
623-
std::sort(UserIDs.begin(), UserIDs.end());
612+
*this << "// " << Ctx.getID(arg);
613+
if (!name.empty()) {
614+
*this << " \"" << name << '\"';
624615
}
616+
if (!arg->use_empty()) {
617+
PrintState.OS.PadToColumn(50);
618+
*this << "// user";
619+
if (std::next(arg->use_begin()) != arg->use_end())
620+
*this << 's';
621+
*this << ": ";
622+
623+
llvm::SmallVector<ID, 32> UserIDs;
624+
for (auto *Op : arg->getUses())
625+
UserIDs.push_back(Ctx.getID(Op->getUser()));
626+
627+
// Display the user ids sorted to give a stable use order in the
628+
// printer's output if we are asked to do so. This makes diffing large
629+
// sections of SIL significantly easier at the expense of not showing
630+
// the _TRUE_ order of the users in the use list.
631+
if (Ctx.sortSIL()) {
632+
std::sort(UserIDs.begin(), UserIDs.end());
633+
}
625634

626-
interleave(UserIDs.begin(), UserIDs.end(),
627-
[&] (ID id) { *this << id; },
628-
[&] { *this << ", "; });
635+
interleave(UserIDs.begin(), UserIDs.end(),
636+
[&] (ID id) { *this << id; },
637+
[&] { *this << ", "; });
638+
}
629639
*this << '\n';
630640
}
631641
}

lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ void ExistentialSpecializerCloner::cloneArguments(
179179
NewF.getLoweredType(NewF.mapTypeIntoContext(GenericParam));
180180
GenericSILType = GenericSILType.getCategoryType(
181181
ArgDesc.Arg->getType().getCategory());
182-
auto *NewArg = ClonedEntryBB->createFunctionArgument(GenericSILType);
182+
auto *NewArg =
183+
ClonedEntryBB->createFunctionArgument(GenericSILType, ArgDesc.Decl);
183184
NewArg->setOwnershipKind(ValueOwnershipKind(
184185
NewF, GenericSILType, ArgDesc.Arg->getArgumentConvention()));
185186
// Determine the Conformances.

test/SILGen/opaque_result_type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public class D {
169169

170170
// CHECK-LABEL: sil [ossa] @$s18opaque_result_type10tupleAsAnyQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s18opaque_result_type10tupleAsAnyQryF", 0) 🦸 {
171171
public func tupleAsAny() -> some Any {
172-
// CHECK-NEXT: bb0(%0 : $*()):
172+
// CHECK: bb0(%0 : $*()):
173173
// CHECK-NEXT: %1 = tuple ()
174174
// CHECK-NEXT: return %1 : $()
175175
return ()

test/SILGen/property_wrappers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func forceHasMemberwiseInit() {
9898
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers17HasMemberwiseInitVACyxGycfC : $@convention(method) <T where T : DefaultInit> (@thin HasMemberwiseInit<T>.Type) -> @out HasMemberwiseInit<T> {
9999

100100
// Initialization of x
101-
// CHECK-NOT: return
101+
// CHECK-NOT: return %
102102
// CHECK: function_ref @$s17property_wrappers17HasMemberwiseInitV2_x33_{{.*}}7WrapperVySbGvpfi : $@convention(thin) <τ_0_0 where τ_0_0 : DefaultInit> () -> Wrapper<Bool>
103103

104104
// Initialization of y

test/SILOptimizer/constant_propagation_stdlib.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct MyInt {
1111
// CHECK-ONONE: return [[RESULT]]
1212
// CHECK-ONONE: } // end sil function '$s27constant_propagation_stdlib15isConcrete_trueyBi1_AA5MyIntVF'
1313
// CHECK-O-LABEL: sil @$s27constant_propagation_stdlib15isConcrete_trueyBi1_AA5MyIntVF : $@convention(thin) (MyInt) -> Builtin.Int1 {
14-
// CHECK-O-NEXT: bb0(
14+
// CHECK-O: bb0(
1515
// CHECK-O-NEXT: [[RESULT:%.*]] = integer_literal $Builtin.Int1, -1
1616
// CHECK-O-NEXT: return [[RESULT]]
1717
// CHECK-O-NEXT: } // end sil function '$s27constant_propagation_stdlib15isConcrete_trueyBi1_AA5MyIntVF'
@@ -84,7 +84,7 @@ public func isConcrete_concrete_caller(_ x: MyInt) -> Builtin.Int1 {
8484
// CHECK-ONONE: return [[RESULT]]
8585
// CHECK-ONONE: } // end sil function '$s27constant_propagation_stdlib4main1xBi1__Bi1_Bi1_tAA5MyIntV_tF'
8686
// CHECK-O-LABEL: sil @$s27constant_propagation_stdlib4main1xBi1__Bi1_Bi1_tAA5MyIntV_tF : $@convention(thin) (MyInt) -> (Builtin.Int1, Builtin.Int1, Builtin.Int1) {
87-
// CHECK-O-NEXT: bb0(
87+
// CHECK-O: bb0(
8888
// CHECK-O-NEXT: [[VALUE:%.*]] = integer_literal $Builtin.Int1, -1
8989
// CHECK-O-NEXT: [[RESULT:%.*]] = tuple ([[VALUE]] : $Builtin.Int1, [[VALUE]] : $Builtin.Int1, [[VALUE]] : $Builtin.Int1)
9090
// CHECK-O-NEXT: return [[RESULT]]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-swift-frontend -module-name main -O -emit-sil -primary-file %s | %FileCheck %s
2+
3+
protocol P {
4+
func foo()
5+
}
6+
7+
public struct Inner {
8+
var x: Int
9+
var y: Int
10+
}
11+
12+
public struct S : P {
13+
var i: Inner
14+
15+
func foo() {
16+
print(i.x)
17+
}
18+
}
19+
20+
// Check that FSO does not crash due to a missing decl on the function argument.
21+
22+
// Following specializations should be done:
23+
// * FSO: existential to protocol constrained generic
24+
// * generic specialization <S>
25+
// * FSO: argument explosion
26+
27+
// CHECK-LABEL: sil shared [noinline] @$s4main6testityyAA1P_pFTf4e_nAA1SV_Tg5Tf4x_n : $@convention(thin) (Int) -> () {
28+
// CHECK-NEXT: // %0 "p"
29+
@inline(never)
30+
func testit(_ p: P) {
31+
p.foo()
32+
}
33+
34+
public func callit(s: S) {
35+
testit(s)
36+
}

0 commit comments

Comments
 (0)