Skip to content

Commit 50b5d61

Browse files
authored
Merge pull request #65593 from hyp/5.9/fix/frt-rr-lookup
[5.9][interop] lookup FRT retain/release functions in top level module
2 parents 6453128 + a90a224 commit 50b5d61

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6767,8 +6767,10 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
67676767
return {CustomRefCountingOperationResult::immortal, nullptr, name};
67686768

67696769
llvm::SmallVector<ValueDecl *, 1> results;
6770-
auto parentModule = ctx.getClangModuleLoader()->getWrapperForModule(
6771-
swiftDecl->getClangDecl()->getOwningModule());
6770+
auto *clangMod = swiftDecl->getClangDecl()->getOwningModule();
6771+
if (clangMod && clangMod->isSubModule())
6772+
clangMod = clangMod->getTopLevelModule();
6773+
auto parentModule = ctx.getClangModuleLoader()->getWrapperForModule(clangMod);
67726774
ctx.lookupInModule(parentModule, name, results);
67736775

67746776
if (results.size() == 1)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -typecheck -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop -disable-availability-checking 2>&1
4+
5+
//--- Inputs/module.modulemap
6+
module Test {
7+
header "test.h"
8+
requires cplusplus
9+
10+
module sub {
11+
header "subtest.h"
12+
13+
export *
14+
}
15+
16+
export *
17+
}
18+
19+
//--- Inputs/test.h
20+
// empty file
21+
22+
//--- Inputs/subtest.h
23+
struct
24+
__attribute__((swift_attr("import_reference")))
25+
__attribute__((swift_attr("retain:retainFn")))
26+
__attribute__((swift_attr("release:releaseFn")))
27+
RefCounted {
28+
static RefCounted *create();
29+
};
30+
31+
void retainFn(RefCounted *);
32+
void releaseFn(RefCounted *);
33+
34+
//--- test.swift
35+
36+
import Test
37+
38+
let x = RefCounted.create()

0 commit comments

Comments
 (0)