Skip to content

Commit e1ff376

Browse files
authored
Merge pull request #65567 from hyp/eng/do-lookup
[interop] lookup FRT retain/release functions in top level module
2 parents 9496125 + 60fd510 commit e1ff376

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
@@ -6761,8 +6761,10 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
67616761
return {CustomRefCountingOperationResult::immortal, nullptr, name};
67626762

67636763
llvm::SmallVector<ValueDecl *, 1> results;
6764-
auto parentModule = ctx.getClangModuleLoader()->getWrapperForModule(
6765-
swiftDecl->getClangDecl()->getOwningModule());
6764+
auto *clangMod = swiftDecl->getClangDecl()->getOwningModule();
6765+
if (clangMod && clangMod->isSubModule())
6766+
clangMod = clangMod->getTopLevelModule();
6767+
auto parentModule = ctx.getClangModuleLoader()->getWrapperForModule(clangMod);
67666768
ctx.lookupInModule(parentModule, name, results);
67676769

67686770
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)