From 73687c9f5fcc8a70ef2cb5a21b23f579babe1827 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 12 Aug 2025 10:08:02 -0700 Subject: [PATCH] [Interop] Test APINotes support for noncopyable types with SwiftDestroyOp. --- test/Interop/C/struct/Inputs/NoncopyableStructs.apinotes | 6 ++++++ test/Interop/C/struct/Inputs/noncopyable-struct.h | 5 +++++ test/Interop/C/struct/noncopyable_structs.swift | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 test/Interop/C/struct/Inputs/NoncopyableStructs.apinotes diff --git a/test/Interop/C/struct/Inputs/NoncopyableStructs.apinotes b/test/Interop/C/struct/Inputs/NoncopyableStructs.apinotes new file mode 100644 index 0000000000000..44bf09e74da51 --- /dev/null +++ b/test/Interop/C/struct/Inputs/NoncopyableStructs.apinotes @@ -0,0 +1,6 @@ +--- +Name: NoncopyableStructs +Tags: +- Name: NonCopyableWithAPINotesDeinit + SwiftCopyable: false + SwiftDestroyOp: freeNonCopyableWithAPINotesDeinit diff --git a/test/Interop/C/struct/Inputs/noncopyable-struct.h b/test/Interop/C/struct/Inputs/noncopyable-struct.h index 321a86469e6b4..71be2de1361ef 100644 --- a/test/Interop/C/struct/Inputs/noncopyable-struct.h +++ b/test/Interop/C/struct/Inputs/noncopyable-struct.h @@ -8,6 +8,10 @@ typedef struct SWIFT_NONCOPYABLE_WITH_DESTROY(freeNonCopyableWithDeinit) NonCopy void *storage; } NonCopyableWithDeinit; +typedef struct NonCopyableWithAPINotesDeinit { + void *storage; +} NonCopyableWithAPINotesDeinit; + typedef struct __attribute__((swift_attr("destroy:freeCopyableType"))) CopyableType { void *storage; } CopyableType; @@ -29,6 +33,7 @@ extern "C" { #endif void freeNonCopyableWithDeinit(NonCopyableWithDeinit ncd); +void freeNonCopyableWithAPINotesDeinit(NonCopyableWithAPINotesDeinit ncd); void freeCopyableType(CopyableType ct); diff --git a/test/Interop/C/struct/noncopyable_structs.swift b/test/Interop/C/struct/noncopyable_structs.swift index 082632ffffac6..d4700fdab74ad 100644 --- a/test/Interop/C/struct/noncopyable_structs.swift +++ b/test/Interop/C/struct/noncopyable_structs.swift @@ -26,11 +26,17 @@ func testNC() { let nc = NonCopyable() // expected-error{{'nc' consumed more than once}} consumeNC(nc) // expected-note{{consumed here}} + let ncAPI = NonCopyableWithAPINotesDeinit() // expected-error{{consumed more than once}} + consumeNCAPI(ncAPI) // expected-note{{consumed here}} + #if ERRORS consumeNC(nc) // expected-note{{consumed again here}} + consumeNCAPI(ncAPI) // expected-note{{consumed again here}} #endif } +func consumeNCAPI(_ nc: consuming NonCopyableWithAPINotesDeinit) { } + func consumeNCWithDeinit(_ nc: consuming NonCopyableWithDeinit) { } func testNCWithDeinit() {