Skip to content

Commit 0505266

Browse files
committed
fix printing for inout type with nullability
1 parent 705e562 commit 0505266

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class CFunctionSignatureTypePrinter
8585
os << knownTypeInfo->name;
8686
if (knownTypeInfo->canBeNullable) {
8787
printNullability(optionalKind);
88-
} else if (isInOutParam) {
88+
}
89+
if (isInOutParam) {
8990
os << (languageMode == swift::OutputLanguageMode::Cxx ? " &" : " *");
9091
}
9192
return true;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// CHECK: SWIFT_EXTERN void $s9Functions8inOutIntyySizF(ptrdiff_t * x) SWIFT_NOEXCEPT SWIFT_CALL; // inOutInt(_:)
88
// CHECK: SWIFT_EXTERN void $s9Functions11inOutTwoIntyySiz_SiztF(ptrdiff_t * x, ptrdiff_t * y) SWIFT_NOEXCEPT SWIFT_CALL; // inOutTwoInt(_:_:)
99
// 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(_:)
1011

1112
// CHECK: inline void inOutInt(swift::Int & x) noexcept {
1213
// CHECK-NEXT: return _impl::$s9Functions8inOutIntyySizF(&x);
@@ -20,6 +21,11 @@
2021
// CHECK-NEXT: return _impl::$s9Functions13inOutTwoParamyySbz_SdztF(&x, &y);
2122
// CHECK-NEXT: }
2223

24+
// CHECK: inline void inoutTypeWithNullability(void const * _Nonnull & x) noexcept {
25+
// CHECK-NEXT: return _impl::$s9Functions24inoutTypeWithNullabilityyySVzF(&x);
26+
// CHECK-NEXT: }
27+
28+
2329
public func inOutInt(_ x: inout Int) { x = Int() }
2430

2531
public func inOutTwoInt(_ x: inout Int, _ y: inout Int) {
@@ -31,3 +37,7 @@ public func inOutTwoParam(_ x: inout Bool, _ y: inout Double) {
3137
y = 3.14
3238
x = !x
3339
}
40+
41+
public func inoutTypeWithNullability(_ x: inout UnsafeRawPointer) {
42+
x += 1
43+
}

test/Interop/SwiftToCxx/functions/swift-primitive-inout-functions-execution.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ int main() {
3939
assert(x);
4040
assert(y == 3.14);
4141
}
42+
43+
{
44+
char c[2] = {'A', 'B'};
45+
const void *p = &c[0];
46+
assert(*static_cast<const char *>(p) == 'A');
47+
inoutTypeWithNullability(p);
48+
assert(*static_cast<const char *>(p) == 'B');
49+
}
4250
}

0 commit comments

Comments
 (0)