Skip to content

Commit

Permalink
Merge pull request #78539 from atrick/fix-silgen-prolog
Browse files Browse the repository at this point in the history
Fix SILGenFunction::emitBasicProlog for @Lifetime with default args.
  • Loading branch information
atrick authored Jan 11, 2025
2 parents 50c4861 + 03ae24d commit d3f1924
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,9 +1643,12 @@ uint16_t SILGenFunction::emitBasicProlog(
emitIndirectErrorParameter(*this, *errorType, *origErrorType, DC);
}

// Parameters with scoped dependencies may lower differently.
// Parameters with scoped dependencies may lower differently. Parameters are
// relative to the current SILGenFunction, not the passed in DeclContext. For
// example, the an argument initializer's DeclContext is the enclosing
// function definition rather that the initializer's generator function.
llvm::SmallPtrSet<ParamDecl *, 2> scopedDependencyParams;
if (auto afd = dyn_cast<AbstractFunctionDecl>(DC)) {
if (auto afd = dyn_cast<AbstractFunctionDecl>(FunctionDC)) {
if (auto deps = afd->getLifetimeDependencies()) {
for (auto &dep : *deps) {
auto scoped = dep.getScopeIndices();
Expand Down
10 changes: 9 additions & 1 deletion test/SILGen/addressable_for_dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Foo { var x: String }
struct Bar { var foo: Foo }

struct Dep: ~Escapable {
var x: Int
var x: Int = 0

@lifetime(immortal)
init() { }
Expand Down Expand Up @@ -98,3 +98,11 @@ extension Bar {
return bar.dependencyOnSelf()
}
}

// CHECK-LABEL: sil {{.*}}@$s28addressable_for_dependencies14defaulArgument1iySi_tFfA_ :
// CHECK-SAME: $@convention(thin) () -> Int {

// CHECK-LABEL: sil {{.*}}@$s28addressable_for_dependencies14defaulArgument1iySi_tF :
// CHECK-SAME: $@convention(thin) (Int) -> @lifetime(borrow 0) () {
@lifetime(borrow i)
func defaulArgument(i: Int = 0) {}

0 comments on commit d3f1924

Please sign in to comment.