Skip to content

Commit 4052991

Browse files
authored
Merge pull request #76668 from swiftlang/gaborh/lifetimebound-off-by-one
[cxx-interop] Fix off-by-one error when importing lifetimebound attrs
2 parents 289a4f5 + 72ce39c commit 4052991

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3880,7 +3880,7 @@ namespace {
38803880
? IndexSubset::get(Impl.SwiftContext,
38813881
scopedLifetimeParamIndicesForReturn)
38823882
: nullptr,
3883-
swiftParams->size(),
3883+
swiftParams->size() + hasSelf,
38843884
/*isImmortal*/ false));
38853885
else if (auto *ctordecl = dyn_cast<clang::CXXConstructorDecl>(decl)) {
38863886
// Assume default constructed view types have no dependencies.

test/Interop/Cxx/class/nonescapable-lifetimebound.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ struct Owner {
3535
View handOutView() const [[clang::lifetimebound]] {
3636
return View(&data);
3737
}
38+
39+
View handOutView2(View v) const [[clang::lifetimebound]] {
40+
return View(&data);
41+
}
3842
};
3943

4044
Owner makeOwner() {
@@ -78,6 +82,7 @@ private:
7882
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0) @autoreleased View
7983
// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0, 1) @autoreleased View
8084
// CHECK: sil [clang Owner.handOutView] {{.*}} : $@convention(cxx_method) (@in_guaranteed Owner) -> _scope(0) @autoreleased View
85+
// CHECK: sil [clang Owner.handOutView2] {{.*}} : $@convention(cxx_method) (View, @in_guaranteed Owner) -> _scope(1) @autoreleased View
8186
// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@guaranteed View, @guaranteed View) -> _inherit(0, 1) @autoreleased View
8287
// CHECK: sil [clang View.init] {{.*}} : $@convention(c) () -> @out View
8388
// CHECK: sil [clang OtherView.init] {{.*}} : $@convention(c) (@guaranteed View) -> _inherit(0) @out OtherView
@@ -93,6 +98,7 @@ public func test() {
9398
let v2 = getViewFromFirst(o, o2)
9499
let _ = getViewFromEither(o, o2)
95100
let _ = o.handOutView()
101+
let _ = o.handOutView2(v1)
96102
let _ = getViewFromEither(v1, v2)
97103
let defaultView = View()
98104
let _ = OtherView(defaultView)

0 commit comments

Comments
 (0)