Skip to content

Commit bd9095e

Browse files
authored
Merge pull request #76733 from fahadnayyar/cxx-interop-frt-retain-release-diagnostics-patch-2
[cxx-interop] Add diagnostic notes when retain/release are not import…
2 parents 33f1860 + d1b380f commit bd9095e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,11 @@ namespace {
26152615
Impl.diagnose(loc,
26162616
diag::foreign_reference_types_cannot_find_retain_release,
26172617
false, retainOperation.name, decl->getNameAsString());
2618+
if (!Impl.SwiftContext.LangOpts
2619+
.DisableExperimentalClangImporterDiagnostics) {
2620+
Impl.diagnoseTopLevelValue(
2621+
DeclName(Impl.SwiftContext.getIdentifier(retainOperation.name)));
2622+
}
26182623
} else if (retainOperation.kind ==
26192624
CustomRefCountingOperationResult::tooManyFound) {
26202625
HeaderLoc loc(decl->getLocation());
@@ -2674,7 +2679,12 @@ namespace {
26742679
Impl.diagnose(loc,
26752680
diag::foreign_reference_types_cannot_find_retain_release,
26762681
true, releaseOperation.name, decl->getNameAsString());
2677-
} else if (releaseOperation.kind ==
2682+
if (!Impl.SwiftContext.LangOpts
2683+
.DisableExperimentalClangImporterDiagnostics) {
2684+
Impl.diagnoseTopLevelValue(
2685+
DeclName(Impl.SwiftContext.getIdentifier(releaseOperation.name)));
2686+
}
2687+
}else if (releaseOperation.kind ==
26782688
CustomRefCountingOperationResult::tooManyFound) {
26792689
HeaderLoc loc(decl->getLocation());
26802690
Impl.diagnose(loc,

test/Interop/Cxx/foreign-reference/invalid-retain-operation-errors.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ void retain2(MultipleRetainReleaseAttrFRT *v);
204204
void release1(MultipleRetainReleaseAttrFRT *v);
205205
void release2(MultipleRetainReleaseAttrFRT *v);
206206

207+
struct
208+
__attribute__((swift_attr("import_reference")))
209+
__attribute__((swift_attr("retain:Uretain")))
210+
__attribute__((swift_attr("release:Urelease")))
211+
UnimportedRetainRelease {};
212+
void Uretain(UnimportedRetainRelease v);
213+
UnimportedRetainRelease Urelease(UnimportedRetainRelease* v);
214+
207215
//--- test.swift
208216

209217
import Test
@@ -284,3 +292,10 @@ public func testMultipleRetainRelease(x: MultipleRetainReleaseFRT) {}
284292
// CHECK: error: reference type 'MultipleRetainReleaseAttrFRT' must have only one 'release:' Swift attribute
285293
@available(macOS 13.3, *)
286294
public func testMultipleRetainRelease(x: MultipleRetainReleaseAttrFRT) {}
295+
296+
// CHECK: error: cannot find retain function 'Uretain' for reference type 'UnimportedRetainRelease'
297+
// CHECK: note: function uses foreign reference type 'UnimportedRetainRelease' as a value in a parameter types which breaks 'swift_shared_reference' contract
298+
// CHECK: error: cannot find release function 'Urelease' for reference type 'UnimportedRetainRelease'
299+
// CHECK: note: function uses foreign reference type 'UnimportedRetainRelease' as a value in the return types which breaks 'swift_shared_reference' contract
300+
@available(macOS 13.3, *)
301+
public func test(x: UnimportedRetainRelease) {}

0 commit comments

Comments
 (0)