Skip to content

Commit 80e0bfc

Browse files
committed
[AddressLowering] ParamDecl's context falls back.
When address lowering rewrites a return to use an indirect convention, it creates a ParamDecl, using the function's decl context. Some functions, such as default argument getters, don't have such contexts, though. In such cases, fall back to module as decl context.
1 parent f6c0773 commit 80e0bfc

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,12 @@ static unsigned insertIndirectReturnArgs(AddressLoweringState &pass) {
553553
auto &astCtx = pass.getModule()->getASTContext();
554554
auto typeCtx = pass.function->getTypeExpansionContext();
555555
auto *declCtx = pass.function->getDeclContext();
556+
if (!declCtx) {
557+
// Fall back to using the module as the decl context if the function
558+
// doesn't have one. The can happen with default argument getters, for
559+
// example.
560+
declCtx = pass.function->getModule().getSwiftModule();
561+
}
556562

557563
unsigned argIdx = 0;
558564
for (auto resultTy : pass.loweredFnConv.getIndirectSILResultTypes(typeCtx)) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -enable-sil-opaque-values -parse-as-library -emit-sil -O -enable-library-evolution %s | %FileCheck %s
2+
3+
public struct Gadget {
4+
// Verify the default accessor's arguments. When AccessPathVerification runs,
5+
// it will be checked that the ParamDecl that AddressLowering synthesizes has a
6+
// non-null decl context.
7+
// CHECK-LABEL: sil @$s25opaque_values_O_resilient6GadgetV5whichA2C5WhichO_tcfC : {{.*}} {
8+
// CHECK: bb0(%0 : $*Gadget, %1 : $*Gadget.Which, %2 : $@thin Gadget.Type):
9+
// CHECK-LABEL: } // end sil function '$s25opaque_values_O_resilient6GadgetV5whichA2C5WhichO_tcfC'
10+
public init(which: Which = .that) {
11+
fatalError()
12+
}
13+
14+
public enum Which {
15+
case that
16+
case this(() -> Gadget)
17+
case theOther
18+
}
19+
}

0 commit comments

Comments
 (0)