Skip to content

Commit a3b9c40

Browse files
Xazax-hunGabor Horvath
authored and
Gabor Horvath
committed
[6.2][cxx-interop] Properly import annotations from functions in namespace scope
Explanation: C++ namespaces imported as Swift enums. This was not accounted for in a condition and that resulted in not importing lifetime annotations for functions that are in namespace scope. This PR fixes that condition. Issue: rdar://149756644 Risk: Low, the fix is very targeted. Testing: Regression test added. Original PR: #80986 Reviewer: @j-hui
1 parent a10356a commit a3b9c40

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,8 @@ namespace {
41904190
return;
41914191

41924192
// FIXME: support C functions imported as members.
4193-
if (result->getImportAsMemberStatus().isImportAsMember() &&
4193+
if (!isClangNamespace(result->getDeclContext()) &&
4194+
result->getImportAsMemberStatus().isImportAsMember() &&
41944195
!isa<clang::CXXMethodDecl, clang::ObjCMethodDecl>(decl))
41954196
return;
41964197

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ struct SWIFT_NONESCAPABLE AggregateView {
109109
const int *member;
110110
};
111111

112+
namespace NS {
113+
View getView(const Owner& owner [[clang::lifetimebound]]) {
114+
return View(&owner.data);
115+
}
116+
}
117+
112118
// CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner
113119
// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
114120
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
@@ -123,6 +129,7 @@ struct SWIFT_NONESCAPABLE AggregateView {
123129
// CHECK: sil [clang getCaptureView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned CaptureView
124130
// CHECK: sil [clang CaptureView.captureView] {{.*}} : $@convention(cxx_method) (View, @lifetime(copy 0) @inout CaptureView) -> ()
125131
// CHECK: sil [clang CaptureView.handOut] {{.*}} : $@convention(cxx_method) (@lifetime(copy 1) @inout View, @in_guaranteed CaptureView) -> ()
132+
// CHECK: sil [clang NS.getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
126133

127134
//--- test.swift
128135

@@ -144,6 +151,7 @@ public func test() {
144151
var cv = getCaptureView(o)
145152
cv.captureView(v1)
146153
cv.handOut(&v1)
154+
var _ = NS.getView(o)
147155
}
148156

149157
public func test2(_ x: AggregateView) {

0 commit comments

Comments
 (0)