Skip to content

Commit fd0dd26

Browse files
authored
Merge pull request #64389 from hyp/eng/SWIFT_INLINE_PRIVATE_HELPER-macro
[interop][SwiftToCxx] use 'SWIFT_INLINE_PRIVATE_HELPER' macro for sta…
2 parents b49f2ef + 94c1de7 commit fd0dd26

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

lib/PrintAsClang/ClangSyntaxPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ void ClangSyntaxPrinter::printInlineForThunk() const {
197197
os << "SWIFT_INLINE_THUNK ";
198198
}
199199

200+
void ClangSyntaxPrinter::printInlineForHelperFunction() const {
201+
os << "SWIFT_INLINE_PRIVATE_HELPER ";
202+
}
203+
200204
void ClangSyntaxPrinter::printNullability(
201205
Optional<OptionalTypeKind> kind, NullabilityPrintKind printKind) const {
202206
if (!kind)

lib/PrintAsClang/ClangSyntaxPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class ClangSyntaxPrinter {
154154
};
155155

156156
void printInlineForThunk() const;
157+
void printInlineForHelperFunction() const;
157158

158159
void printNullability(
159160
Optional<OptionalTypeKind> kind,

lib/PrintAsClang/PrintClangValueType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void ClangValueTypePrinter::printValueTypeDecl(
442442

443443
os << " template<class T>\n";
444444
os << " static ";
445-
ClangSyntaxPrinter(os).printInlineForThunk();
445+
ClangSyntaxPrinter(os).printInlineForHelperFunction();
446446
printCxxTypeName(os, typeDecl, moduleContext);
447447
printGenericParamRefs(os);
448448
os << " returnNewValue(T callable) {\n";

lib/PrintAsClang/_SwiftCxxInteroperability.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,31 @@
2828
# define SWIFT_CALL __attribute__((swiftcall))
2929
#endif
3030

31-
/// The `SWIFT_INLINE_THUNK` macro is applied on the inline function thunks in
32-
/// the header that represents a C/C++ Swift module interface generated by the
33-
/// Swift compiler.
3431
#if __has_attribute(always_inline) && __has_attribute(nodebug)
32+
#define SWIFT_INLINE_THUNK_ATTRIBUTES \
33+
__attribute__((always_inline)) __attribute__((nodebug))
3534
#if defined(DEBUG) && __has_attribute(used)
3635
// Additional 'used' attribute is used in debug mode to make inline thunks
3736
// accessible to LLDB.
38-
#define SWIFT_INLINE_THUNK_ATTRIBUTES \
39-
__attribute__((always_inline)) __attribute__((nodebug)) \
40-
__attribute__((used))
37+
#define SWIFT_INLINE_THUNK_USED_ATTRIBUTE __attribute__((used))
4138
#else
42-
#define SWIFT_INLINE_THUNK_ATTRIBUTES \
43-
__attribute__((always_inline)) __attribute__((nodebug))
39+
#define SWIFT_INLINE_THUNK_USED_ATTRIBUTE
4440
#endif
4541
#else
4642
#define SWIFT_INLINE_THUNK_ATTRIBUTES
43+
#define SWIFT_INLINE_THUNK_USED_ATTRIBUTE
4744
#endif
4845

49-
#define SWIFT_INLINE_THUNK inline SWIFT_INLINE_THUNK_ATTRIBUTES
46+
/// The `SWIFT_INLINE_THUNK` macro is applied on the inline function thunks in
47+
/// the header that represents a C/C++ Swift module interface generated by the
48+
/// Swift compiler.
49+
#define SWIFT_INLINE_THUNK \
50+
inline SWIFT_INLINE_THUNK_ATTRIBUTES SWIFT_INLINE_THUNK_USED_ATTRIBUTE
51+
52+
/// The `SWIFT_INLINE_PRIVATE_HELPER` macro is applied on the helper / utility
53+
/// functions in the header that represents a C/C++ Swift module interface
54+
/// generated by the Swift compiler.
55+
#define SWIFT_INLINE_PRIVATE_HELPER inline SWIFT_INLINE_THUNK_ATTRIBUTES
5056

5157
/// The `SWIFT_SYMBOL_MODULE` and `SWIFT_SYMBOL_MODULE_USR` macros apply
5258
/// `external_source_symbol` Clang attributes to C++ declarations that represent

test/Interop/SwiftToCxx/generics/generic-struct-in-cxx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public func inoutConcretePair(_ x: UInt16, _ y: inout GenericPair<UInt16, UInt16
255255
// CHECK-NEXT: static SWIFT_INLINE_THUNK char * _Nonnull getOpaquePointer(GenericPair<T_0_0, T_0_1> &object) { return object._getOpaquePointer(); }
256256
// CHECK-NEXT: static SWIFT_INLINE_THUNK const char * _Nonnull getOpaquePointer(const GenericPair<T_0_0, T_0_1> &object) { return object._getOpaquePointer(); }
257257
// CHECK-NEXT: template<class T>
258-
// CHECK-NEXT: static SWIFT_INLINE_THUNK GenericPair<T_0_0, T_0_1> returnNewValue(T callable) {
258+
// CHECK-NEXT: static SWIFT_INLINE_PRIVATE_HELPER GenericPair<T_0_0, T_0_1> returnNewValue(T callable) {
259259
// CHECK-NEXT: auto result = GenericPair<T_0_0, T_0_1>::_make();
260260
// CHECK-NEXT: callable(result._getOpaquePointer());
261261
// CHECK-NEXT: return result;

test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %FileCheck %s < %t/Swift.h
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/Swift.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -Wno-unused-private-field -Wno-unused-function -Wc++98-compat-extra-semi)
6+
// RUN: %check-interop-cxx-header-in-clang(%t/Swift.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -Wno-unused-private-field -Wno-unused-function -Wc++98-compat-extra-semi -DDEBUG=1)
67

78
// CHECK: namespace swift SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("swift") {
89

test/Interop/SwiftToCxx/structs/swift-struct-in-cxx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
// CHECK-NEXT: static SWIFT_INLINE_THUNK char * _Nonnull getOpaquePointer(StructWithIntField &object) { return object._getOpaquePointer(); }
6565
// CHECK-NEXT: static SWIFT_INLINE_THUNK const char * _Nonnull getOpaquePointer(const StructWithIntField &object) { return object._getOpaquePointer(); }
6666
// CHECK-NEXT: template<class T>
67-
// CHECK-NEXT: static SWIFT_INLINE_THUNK StructWithIntField returnNewValue(T callable) {
67+
// CHECK-NEXT: static SWIFT_INLINE_PRIVATE_HELPER StructWithIntField returnNewValue(T callable) {
6868
// CHECK-NEXT: auto result = StructWithIntField::_make();
6969
// CHECK-NEXT: callable(result._getOpaquePointer());
7070
// CHECK-NEXT: return result;

0 commit comments

Comments
 (0)