Skip to content

Commit d3f1924

Browse files
authored
Merge pull request #78539 from atrick/fix-silgen-prolog
Fix SILGenFunction::emitBasicProlog for @Lifetime with default args.
2 parents 50c4861 + 03ae24d commit d3f1924

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,12 @@ uint16_t SILGenFunction::emitBasicProlog(
16431643
emitIndirectErrorParameter(*this, *errorType, *origErrorType, DC);
16441644
}
16451645

1646-
// Parameters with scoped dependencies may lower differently.
1646+
// Parameters with scoped dependencies may lower differently. Parameters are
1647+
// relative to the current SILGenFunction, not the passed in DeclContext. For
1648+
// example, the an argument initializer's DeclContext is the enclosing
1649+
// function definition rather that the initializer's generator function.
16471650
llvm::SmallPtrSet<ParamDecl *, 2> scopedDependencyParams;
1648-
if (auto afd = dyn_cast<AbstractFunctionDecl>(DC)) {
1651+
if (auto afd = dyn_cast<AbstractFunctionDecl>(FunctionDC)) {
16491652
if (auto deps = afd->getLifetimeDependencies()) {
16501653
for (auto &dep : *deps) {
16511654
auto scoped = dep.getScopeIndices();

test/SILGen/addressable_for_dependencies.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct Foo { var x: String }
99
struct Bar { var foo: Foo }
1010

1111
struct Dep: ~Escapable {
12-
var x: Int
12+
var x: Int = 0
1313

1414
@lifetime(immortal)
1515
init() { }
@@ -98,3 +98,11 @@ extension Bar {
9898
return bar.dependencyOnSelf()
9999
}
100100
}
101+
102+
// CHECK-LABEL: sil {{.*}}@$s28addressable_for_dependencies14defaulArgument1iySi_tFfA_ :
103+
// CHECK-SAME: $@convention(thin) () -> Int {
104+
105+
// CHECK-LABEL: sil {{.*}}@$s28addressable_for_dependencies14defaulArgument1iySi_tF :
106+
// CHECK-SAME: $@convention(thin) (Int) -> @lifetime(borrow 0) () {
107+
@lifetime(borrow i)
108+
func defaulArgument(i: Int = 0) {}

0 commit comments

Comments
 (0)