Skip to content

Commit 3f1dd13

Browse files
authored
Merge pull request #60300 from WANGJIEKE/cxx-interop-fix-pointer-annotation
[Interop][SwiftToCxx] Add pointer nullability annotation for inout function
2 parents ce93261 + 19c7d79 commit 3f1dd13

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class CFunctionSignatureTypePrinter
101101
moduleContext(moduleContext), typeUseKind(typeUseKind) {}
102102

103103
void printInoutTypeModifier() {
104-
os << (languageMode == swift::OutputLanguageMode::Cxx ? " &" : " *");
104+
os << (languageMode == swift::OutputLanguageMode::Cxx ? " &"
105+
: " * _Nonnull");
105106
}
106107

107108
bool printIfKnownSimpleType(const TypeDecl *typeDecl,

test/Interop/SwiftToCxx/functions/swift-primitive-inout-functions-cxx-bridging.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
66

7-
// CHECK: SWIFT_EXTERN void $s9Functions8inOutIntyySizF(ptrdiff_t * x) SWIFT_NOEXCEPT SWIFT_CALL; // inOutInt(_:)
8-
// CHECK: SWIFT_EXTERN void $s9Functions11inOutTwoIntyySiz_SiztF(ptrdiff_t * x, ptrdiff_t * y) SWIFT_NOEXCEPT SWIFT_CALL; // inOutTwoInt(_:_:)
9-
// CHECK: SWIFT_EXTERN void $s9Functions13inOutTwoParamyySbz_SdztF(bool * x, double * y) SWIFT_NOEXCEPT SWIFT_CALL; // inOutTwoParam(_:_:)
10-
// CHECK: SWIFT_EXTERN void $s9Functions24inoutTypeWithNullabilityyySVzF(void const * _Nonnull * x) SWIFT_NOEXCEPT SWIFT_CALL; // inoutTypeWithNullability(_:)
11-
// CHECK: SWIFT_EXTERN void $s9Functions25inoutUnsafeGenericPointeryySPys5Int32VGzF(int32_t const * _Nonnull * x) SWIFT_NOEXCEPT SWIFT_CALL; // inoutUnsafeGenericPointer(_:)
7+
// CHECK: SWIFT_EXTERN void $s9Functions8inOutIntyySizF(ptrdiff_t * _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // inOutInt(_:)
8+
// CHECK: SWIFT_EXTERN void $s9Functions11inOutTwoIntyySiz_SiztF(ptrdiff_t * _Nonnull x, ptrdiff_t * _Nonnull y) SWIFT_NOEXCEPT SWIFT_CALL; // inOutTwoInt(_:_:)
9+
// CHECK: SWIFT_EXTERN void $s9Functions13inOutTwoParamyySbz_SdztF(bool * _Nonnull x, double * _Nonnull y) SWIFT_NOEXCEPT SWIFT_CALL; // inOutTwoParam(_:_:)
10+
// CHECK: SWIFT_EXTERN void $s9Functions24inoutTypeWithNullabilityyySVzF(void const * _Nonnull * _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // inoutTypeWithNullability(_:)
11+
// CHECK: SWIFT_EXTERN void $s9Functions25inoutUnsafeGenericPointeryySPys5Int32VGzF(int32_t const * _Nonnull * _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // inoutUnsafeGenericPointer(_:)
1212

1313
// CHECK: inline void inOutInt(swift::Int & x) noexcept {
1414
// CHECK-NEXT: return _impl::$s9Functions8inOutIntyySizF(&x);

0 commit comments

Comments
 (0)