Skip to content

Commit 72ce39c

Browse files
author
Gabor Horvath
committed
[cxx-interop] Fix off-by-one error when importing lifetimebound attrs
1 parent dacdb8f commit 72ce39c

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
@@ -26,6 +26,10 @@ struct Owner {
2626
View handOutView() const [[clang::lifetimebound]] {
2727
return View(&data);
2828
}
29+
30+
View handOutView2(View v) const [[clang::lifetimebound]] {
31+
return View(&data);
32+
}
2933
};
3034

3135
Owner makeOwner() {
@@ -69,6 +73,7 @@ private:
6973
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0) @autoreleased View
7074
// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0, 1) @autoreleased View
7175
// CHECK: sil [clang Owner.handOutView] {{.*}} : $@convention(cxx_method) (@in_guaranteed Owner) -> _scope(0) @autoreleased View
76+
// CHECK: sil [clang Owner.handOutView2] {{.*}} : $@convention(cxx_method) (View, @in_guaranteed Owner) -> _scope(1) @autoreleased View
7277
// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@guaranteed View, @guaranteed View) -> _inherit(0, 1) @autoreleased View
7378
// CHECK: sil [clang View.init] {{.*}} : $@convention(c) () -> @out View
7479

@@ -83,6 +88,7 @@ public func test() {
8388
let v2 = getViewFromFirst(o, o2)
8489
let _ = getViewFromEither(o, o2)
8590
let _ = o.handOutView()
91+
let _ = o.handOutView2(v1)
8692
let _ = getViewFromEither(v1, v2)
8793
let defaultView = View()
8894
}

0 commit comments

Comments
 (0)