Skip to content

Commit 845a1bb

Browse files
author
Gabor Horvath
committed
[cxx-interop] Add test for lifetimebound annotation in ctor
There was also an off by one error in this case.
1 parent d3c5149 commit 845a1bb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,7 @@ namespace {
38473847
return;
38483848

38493849
auto swiftParams = result->getParameters();
3850-
bool hasSelf = result->hasImplicitSelfDecl();
3850+
bool hasSelf = result->hasImplicitSelfDecl() && !isa<ConstructorDecl>(result);
38513851
SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;
38523852
SmallBitVector inheritLifetimeParamIndicesForReturn(swiftParams->size() +
38533853
hasSelf);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ struct SWIFT_NONESCAPABLE View {
1616
View() : member(nullptr) {}
1717
View(const int *p [[clang::lifetimebound]]) : member(p) {}
1818
View(const View&) = default;
19+
private:
20+
const int *member;
21+
friend struct OtherView;
22+
};
23+
24+
struct SWIFT_NONESCAPABLE OtherView {
25+
OtherView() : member(nullptr) {}
26+
OtherView(View v [[clang::lifetimebound]]) : member(v.member) {}
27+
OtherView(const OtherView&) = default;
1928
private:
2029
const int *member;
2130
};
@@ -68,14 +77,15 @@ private:
6877
const int *member;
6978
};
7079

71-
// CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner
80+
// CHECK: sil [clang makeOwner] {{.*}} : $@convention(c) () -> Owner
7281
// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> _scope(0) @autoreleased View
7382
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0) @autoreleased View
7483
// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0, 1) @autoreleased View
7584
// CHECK: sil [clang Owner.handOutView] {{.*}} : $@convention(cxx_method) (@in_guaranteed Owner) -> _scope(0) @autoreleased View
7685
// CHECK: sil [clang Owner.handOutView2] {{.*}} : $@convention(cxx_method) (View, @in_guaranteed Owner) -> _scope(1) @autoreleased View
7786
// CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@guaranteed View, @guaranteed View) -> _inherit(0, 1) @autoreleased View
7887
// CHECK: sil [clang View.init] {{.*}} : $@convention(c) () -> @out View
88+
// CHECK: sil [clang OtherView.init] {{.*}} : $@convention(c) (@guaranteed View) -> _inherit(0) @out OtherView
7989

8090
//--- test.swift
8191

@@ -91,4 +101,5 @@ public func test() {
91101
let _ = o.handOutView2(v1)
92102
let _ = getViewFromEither(v1, v2)
93103
let defaultView = View()
104+
let _ = OtherView(defaultView)
94105
}

0 commit comments

Comments
 (0)