From 72ce39ce0716c6aba157c2b33696965ba2c8d7a7 Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Tue, 24 Sep 2024 12:01:26 +0100 Subject: [PATCH] [cxx-interop] Fix off-by-one error when importing lifetimebound attrs --- lib/ClangImporter/ImportDecl.cpp | 2 +- test/Interop/Cxx/class/nonescapable-lifetimebound.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index ae5d544f312d4..f907eaaf63457 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -3880,7 +3880,7 @@ namespace { ? IndexSubset::get(Impl.SwiftContext, scopedLifetimeParamIndicesForReturn) : nullptr, - swiftParams->size(), + swiftParams->size() + hasSelf, /*isImmortal*/ false)); else if (auto *ctordecl = dyn_cast(decl)) { // Assume default constructed view types have no dependencies. diff --git a/test/Interop/Cxx/class/nonescapable-lifetimebound.swift b/test/Interop/Cxx/class/nonescapable-lifetimebound.swift index d7841ca873b33..4afb28b7c5927 100644 --- a/test/Interop/Cxx/class/nonescapable-lifetimebound.swift +++ b/test/Interop/Cxx/class/nonescapable-lifetimebound.swift @@ -26,6 +26,10 @@ struct Owner { View handOutView() const [[clang::lifetimebound]] { return View(&data); } + + View handOutView2(View v) const [[clang::lifetimebound]] { + return View(&data); + } }; Owner makeOwner() { @@ -69,6 +73,7 @@ private: // CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0) @autoreleased View // CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> _scope(0, 1) @autoreleased View // CHECK: sil [clang Owner.handOutView] {{.*}} : $@convention(cxx_method) (@in_guaranteed Owner) -> _scope(0) @autoreleased View +// CHECK: sil [clang Owner.handOutView2] {{.*}} : $@convention(cxx_method) (View, @in_guaranteed Owner) -> _scope(1) @autoreleased View // CHECK: sil [clang getViewFromEither] {{.*}} : $@convention(c) (@guaranteed View, @guaranteed View) -> _inherit(0, 1) @autoreleased View // CHECK: sil [clang View.init] {{.*}} : $@convention(c) () -> @out View @@ -83,6 +88,7 @@ public func test() { let v2 = getViewFromFirst(o, o2) let _ = getViewFromEither(o, o2) let _ = o.handOutView() + let _ = o.handOutView2(v1) let _ = getViewFromEither(v1, v2) let defaultView = View() } \ No newline at end of file