Skip to content

Commit 81a9cad

Browse files
committed
[interop] generate C interfaces for Swift top-level functions that use primitive types
1 parent e909112 commit 81a9cad

File tree

9 files changed

+298
-43
lines changed

9 files changed

+298
-43
lines changed

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -643,25 +643,35 @@ void swift::printModuleContentsAsCxx(
643643
raw_ostream &os, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
644644
ModuleDecl &M) {
645645
using cxx_synthesis::CxxPrinter;
646+
647+
std::string moduleContentsBuf;
648+
llvm::raw_string_ostream moduleOS{moduleContentsBuf};
649+
std::string modulePrologueBuf;
650+
llvm::raw_string_ostream prologueOS{modulePrologueBuf};
651+
652+
ModuleWriter(moduleOS, prologueOS, imports, M, getRequiredAccess(M),
653+
OutputLanguageMode::Cxx)
654+
.write();
655+
656+
// FIXME: refactor.
657+
if (!prologueOS.str().empty()) {
658+
os << "#endif\n";
659+
os << "#ifdef __cplusplus\n";
660+
os << "namespace ";
661+
M.ValueDecl::getName().print(os);
662+
os << " {\n";
663+
os << "namespace " << cxx_synthesis::getCxxImplNamespaceName() << " {\n";
664+
os << "#endif\n\n";
665+
666+
os << prologueOS.str();
667+
668+
os << "\n#ifdef __cplusplus\n";
669+
os << "}\n";
670+
os << "}\n";
671+
}
672+
646673
// Construct a C++ namespace for the module.
647674
CxxPrinter(os).printNamespace(
648675
[&](raw_ostream &os) { M.ValueDecl::getName().print(os); },
649-
[&](raw_ostream &os) {
650-
std::string moduleContentsBuf;
651-
llvm::raw_string_ostream moduleOS{moduleContentsBuf};
652-
std::string modulePrologueBuf;
653-
llvm::raw_string_ostream prologueOS{modulePrologueBuf};
654-
655-
ModuleWriter(moduleOS, prologueOS, imports, M, getRequiredAccess(M),
656-
OutputLanguageMode::Cxx)
657-
.write();
658-
659-
// The module's prologue contains implementation details,
660-
// like extern "C" symbols for the referenced Swift functions.
661-
CxxPrinter(os).printNamespace(
662-
cxx_synthesis::getCxxImplNamespaceName(),
663-
[&](raw_ostream &os) { os << prologueOS.str(); });
664-
665-
os << moduleOS.str();
666-
});
676+
[&](raw_ostream &os) { os << moduleOS.str(); });
667677
}

lib/PrintAsClang/PrimitiveTypeMapping.cpp

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
2222
assert(mappedTypeNames.empty() && "expected empty type map");
2323
#define MAP(SWIFT_NAME, CLANG_REPR, NEEDS_NULLABILITY) \
2424
mappedTypeNames[{ctx.StdlibModuleName, ctx.getIdentifier(#SWIFT_NAME)}] = { \
25-
CLANG_REPR, NEEDS_NULLABILITY}
25+
CLANG_REPR, \
26+
Optional<StringRef>(CLANG_REPR), \
27+
NEEDS_NULLABILITY \
28+
}
29+
#define MAP_C(SWIFT_NAME, OBJC_REPR, C_REPR, NEEDS_NULLABILITY) \
30+
mappedTypeNames[{ctx.StdlibModuleName, ctx.getIdentifier(#SWIFT_NAME)}] = { \
31+
OBJC_REPR, Optional<StringRef>(C_REPR), NEEDS_NULLABILITY}
2632

2733
MAP(CBool, "bool", false);
2834

@@ -60,53 +66,74 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
6066
MAP(Float32, "float", false);
6167
MAP(Float64, "double", false);
6268

63-
MAP(Int, "NSInteger", false);
64-
MAP(UInt, "NSUInteger", false);
65-
MAP(Bool, "BOOL", false);
69+
MAP_C(Int, "NSInteger", "ptrdiff_t", false);
70+
MAP_C(UInt, "NSUInteger", "size_t", false);
71+
MAP_C(Bool, "BOOL", "bool", false);
6672

6773
MAP(OpaquePointer, "void *", true);
6874
MAP(UnsafeRawPointer, "void const *", true);
6975
MAP(UnsafeMutableRawPointer, "void *", true);
7076

7177
Identifier ID_ObjectiveC = ctx.Id_ObjectiveC;
72-
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier("ObjCBool")}] = {"BOOL",
73-
false};
74-
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier("Selector")}] = {"SEL",
75-
true};
78+
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier("ObjCBool")}] = {
79+
"BOOL", None, false};
80+
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier("Selector")}] = {
81+
"SEL", None, true};
7682
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier(ctx.getSwiftName(
7783
KnownFoundationEntity::NSZone))}] = {
78-
"struct _NSZone *", true};
84+
"struct _NSZone *", None, true};
7985

8086
mappedTypeNames[{ctx.Id_Darwin, ctx.getIdentifier("DarwinBoolean")}] = {
81-
"Boolean", false};
87+
"Boolean", None, false};
8288

83-
mappedTypeNames[{ctx.Id_CoreGraphics, ctx.Id_CGFloat}] = {"CGFloat", false};
89+
mappedTypeNames[{ctx.Id_CoreGraphics, ctx.Id_CGFloat}] = {"CGFloat", None,
90+
false};
8491

85-
mappedTypeNames[{ctx.Id_CoreFoundation, ctx.Id_CGFloat}] = {"CGFloat", false};
92+
mappedTypeNames[{ctx.Id_CoreFoundation, ctx.Id_CGFloat}] = {"CGFloat", None,
93+
false};
8694

8795
// Use typedefs we set up for SIMD vector types.
8896
#define MAP_SIMD_TYPE(BASENAME, _, __) \
8997
mappedTypeNames[{ctx.Id_simd, ctx.getIdentifier(#BASENAME "2")}] = { \
90-
"swift_" #BASENAME "2", false}; \
98+
"swift_" #BASENAME "2", Optional<StringRef>("swift_" #BASENAME "2"), \
99+
false}; \
91100
mappedTypeNames[{ctx.Id_simd, ctx.getIdentifier(#BASENAME "3")}] = { \
92-
"swift_" #BASENAME "3", false}; \
101+
"swift_" #BASENAME "3", Optional<StringRef>("swift_" #BASENAME "3"), \
102+
false}; \
93103
mappedTypeNames[{ctx.Id_simd, ctx.getIdentifier(#BASENAME "4")}] = { \
94-
"swift_" #BASENAME "4", false};
104+
"swift_" #BASENAME "4", Optional<StringRef>("swift_" #BASENAME "4"), \
105+
false};
95106
#include "swift/ClangImporter/SIMDMappedTypes.def"
96107
static_assert(SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4,
97108
"must add or remove special name mappings if max number of "
98109
"SIMD elements is changed");
99110
}
100111

101-
Optional<PrimitiveTypeMapping::ObjCClangTypeInfo>
102-
PrimitiveTypeMapping::getKnownObjCTypeInfo(const TypeDecl *typeDecl) {
112+
PrimitiveTypeMapping::ClangTypeInfo *
113+
PrimitiveTypeMapping::getMappedTypeInfoOrNull(const TypeDecl *typeDecl) {
103114
if (mappedTypeNames.empty())
104115
initialize(typeDecl->getASTContext());
105116

106117
Identifier moduleName = typeDecl->getModuleContext()->getName();
107118
Identifier name = typeDecl->getName();
108119
auto iter = mappedTypeNames.find({moduleName, name});
109120
if (iter == mappedTypeNames.end())
110-
return None;
111-
return ObjCClangTypeInfo{iter->second.objcName, iter->second.canBeNullable};
121+
return nullptr;
122+
return &iter->second;
123+
}
124+
125+
Optional<PrimitiveTypeMapping::ObjCClangTypeInfo>
126+
PrimitiveTypeMapping::getKnownObjCTypeInfo(const TypeDecl *typeDecl) {
127+
if (auto *typeInfo = getMappedTypeInfoOrNull(typeDecl))
128+
return ObjCClangTypeInfo{typeInfo->objcName, typeInfo->canBeNullable};
129+
return None;
130+
}
131+
132+
Optional<PrimitiveTypeMapping::CClangTypeInfo>
133+
PrimitiveTypeMapping::getKnownCTypeInfo(const TypeDecl *typeDecl) {
134+
if (auto *typeInfo = getMappedTypeInfoOrNull(typeDecl)) {
135+
if (typeInfo->cName)
136+
return CClangTypeInfo{*typeInfo->cName, typeInfo->canBeNullable};
137+
}
138+
return None;
112139
}

lib/PrintAsClang/PrimitiveTypeMapping.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,28 @@ class PrimitiveTypeMapping {
3939
/// primitive type declaration, or \c None if no such type name exists.
4040
Optional<ObjCClangTypeInfo> getKnownObjCTypeInfo(const TypeDecl *typeDecl);
4141

42+
struct CClangTypeInfo {
43+
StringRef name;
44+
bool canBeNullable;
45+
};
46+
47+
/// Returns the C type name and nullability for the given Swift
48+
/// primitive type declaration, or \c None if no such type name exists.
49+
Optional<CClangTypeInfo> getKnownCTypeInfo(const TypeDecl *typeDecl);
50+
4251
private:
4352
void initialize(ASTContext &ctx);
4453

4554
struct ClangTypeInfo {
4655
// The Objective-C name of the Swift type.
4756
StringRef objcName;
57+
// The C name of the Swift type.
58+
Optional<StringRef> cName;
4859
bool canBeNullable;
4960
};
5061

62+
ClangTypeInfo *getMappedTypeInfoOrNull(const TypeDecl *typeDecl);
63+
5164
/// A map from {Module, TypeName} pairs to {C name, C nullability} pairs.
5265
///
5366
/// This is populated on first use with a list of known Swift types that are

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CFunctionSignatureTypePrinter
3434

3535
bool printIfKnownSimpleType(const TypeDecl *typeDecl,
3636
Optional<OptionalTypeKind> optionalKind) {
37-
auto knownTypeInfo = typeMapping.getKnownObjCTypeInfo(typeDecl);
37+
auto knownTypeInfo = typeMapping.getKnownCTypeInfo(typeDecl);
3838
if (!knownTypeInfo)
3939
return false;
4040
os << knownTypeInfo->name;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -clang-header-expose-public-decls -emit-clang-header-path %t/functions.h
3+
// RUN: %FileCheck %s < %t/functions.h
4+
5+
// RUN: %check-interop-c-header-in-clang(%t/functions.h)
6+
7+
// CHECK: SWIFT_EXTERN float $s9Functions16passThrougCFloatyS2fF(float x) SWIFT_NOEXCEPT SWIFT_CALL;
8+
// CHECK-NEXT: SWIFT_EXTERN bool $s9Functions15passThroughBoolyS2bF(bool x) SWIFT_NOEXCEPT SWIFT_CALL;
9+
// CHECK-NEXT: SWIFT_EXTERN bool $s9Functions16passThroughCBoolyS2bF(bool x) SWIFT_NOEXCEPT SWIFT_CALL;
10+
// CHECK-NEXT: SWIFT_EXTERN char $s9Functions16passThroughCCharys4Int8VADF(char x) SWIFT_NOEXCEPT SWIFT_CALL;
11+
// CHECK-NEXT: SWIFT_EXTERN char16_t $s9Functions18passThroughCChar16ys6UInt16VADF(char16_t x) SWIFT_NOEXCEPT SWIFT_CALL;
12+
// CHECK-NEXT: SWIFT_EXTERN char32_t $s9Functions18passThroughCChar32ys7UnicodeO6ScalarVAFF(char32_t x) SWIFT_NOEXCEPT SWIFT_CALL;
13+
// CHECK-NEXT: SWIFT_EXTERN double $s9Functions18passThroughCDoubleyS2dF(double x) SWIFT_NOEXCEPT SWIFT_CALL;
14+
// CHECK-NEXT: SWIFT_EXTERN int $s9Functions15passThroughCIntys5Int32VADF(int x) SWIFT_NOEXCEPT SWIFT_CALL;
15+
// CHECK-NEXT: SWIFT_EXTERN long $s9Functions16passThroughCLongyS2iF(long x) SWIFT_NOEXCEPT SWIFT_CALL;
16+
// CHECK-NEXT: SWIFT_EXTERN long long $s9Functions20passThroughCLongLongys5Int64VADF(long long x) SWIFT_NOEXCEPT SWIFT_CALL;
17+
// CHECK-NEXT: SWIFT_EXTERN short $s9Functions17passThroughCShortys5Int16VADF(short x) SWIFT_NOEXCEPT SWIFT_CALL;
18+
// CHECK-NEXT: SWIFT_EXTERN signed char $s9Functions22passThroughCSignedCharys4Int8VADF(signed char x) SWIFT_NOEXCEPT SWIFT_CALL;
19+
// CHECK-NEXT: SWIFT_EXTERN unsigned int $s9Functions23passThroughCUnsignedIntys6UInt32VADF(unsigned int x) SWIFT_NOEXCEPT SWIFT_CALL;
20+
// CHECK-NEXT: SWIFT_EXTERN unsigned long $s9Functions24passThroughCUnsignedLongyS2uF(unsigned long x) SWIFT_NOEXCEPT SWIFT_CALL;
21+
// CHECK-NEXT: SWIFT_EXTERN unsigned long long $s9Functions024passThroughCUnsignedLongE0ys6UInt64VADF(unsigned long long x) SWIFT_NOEXCEPT SWIFT_CALL;
22+
// CHECK-NEXT: SWIFT_EXTERN unsigned short $s9Functions25passThroughCUnsignedShortys6UInt16VADF(unsigned short x) SWIFT_NOEXCEPT SWIFT_CALL;
23+
// CHECK-NEXT: SWIFT_EXTERN unsigned char $s9Functions30passThroughCUnsignedSignedCharys5UInt8VADF(unsigned char x) SWIFT_NOEXCEPT SWIFT_CALL;
24+
// CHECK-NEXT: SWIFT_EXTERN wchar_t $s9Functions20passThroughCWideCharys7UnicodeO6ScalarVAFF(wchar_t x) SWIFT_NOEXCEPT SWIFT_CALL;
25+
// CHECK-NEXT: SWIFT_EXTERN double $s9Functions17passThroughDoubleyS2dF(double x) SWIFT_NOEXCEPT SWIFT_CALL;
26+
// CHECK-NEXT: SWIFT_EXTERN float $s9Functions16passThroughFloatyS2fF(float x) SWIFT_NOEXCEPT SWIFT_CALL;
27+
// CHECK-NEXT: SWIFT_EXTERN float $s9Functions18passThroughFloat32yS2fF(float x) SWIFT_NOEXCEPT SWIFT_CALL;
28+
// CHECK-NEXT: SWIFT_EXTERN double $s9Functions18passThroughFloat64yS2dF(double x) SWIFT_NOEXCEPT SWIFT_CALL;
29+
// CHECK-NEXT: SWIFT_EXTERN ptrdiff_t $s9Functions14passThroughIntyS2iF(ptrdiff_t x) SWIFT_NOEXCEPT SWIFT_CALL;
30+
// CHECK-NEXT: SWIFT_EXTERN int16_t $s9Functions16passThroughInt16ys0D0VADF(int16_t x) SWIFT_NOEXCEPT SWIFT_CALL;
31+
// CHECK-NEXT: SWIFT_EXTERN int32_t $s9Functions16passThroughInt32ys0D0VADF(int32_t x) SWIFT_NOEXCEPT SWIFT_CALL;
32+
// CHECK-NEXT: SWIFT_EXTERN int64_t $s9Functions16passThroughInt64ys0D0VADF(int64_t x) SWIFT_NOEXCEPT SWIFT_CALL;
33+
// CHECK-NEXT: SWIFT_EXTERN int8_t $s9Functions15passThroughInt8ys0D0VADF(int8_t x) SWIFT_NOEXCEPT SWIFT_CALL;
34+
// CHECK-NEXT: SWIFT_EXTERN void * $s9Functions24passThroughOpaquePointerys0dE0VADF(void * x) SWIFT_NOEXCEPT SWIFT_CALL;
35+
// CHECK-NEXT: SWIFT_EXTERN size_t $s9Functions15passThroughUIntyS2uF(size_t x) SWIFT_NOEXCEPT SWIFT_CALL;
36+
// CHECK-NEXT: SWIFT_EXTERN uint16_t $s9Functions17passThroughUInt16ys0D0VADF(uint16_t x) SWIFT_NOEXCEPT SWIFT_CALL;
37+
// CHECK-NEXT: SWIFT_EXTERN uint32_t $s9Functions17passThroughUInt32ys0D0VADF(uint32_t x) SWIFT_NOEXCEPT SWIFT_CALL;
38+
// CHECK-NEXT: SWIFT_EXTERN uint64_t $s9Functions17passThroughUInt64ys0D0VADF(uint64_t x) SWIFT_NOEXCEPT SWIFT_CALL;
39+
// CHECK-NEXT: SWIFT_EXTERN uint8_t $s9Functions16passThroughUInt8ys0D0VADF(uint8_t x) SWIFT_NOEXCEPT SWIFT_CALL;
40+
// CHECK-NEXT: SWIFT_EXTERN void * $s9Functions34passThroughUnsafeMutableRawPointeryS2vF(void * x) SWIFT_NOEXCEPT SWIFT_CALL;
41+
// CHECK-NEXT: SWIFT_EXTERN void const * $s9Functions27passThroughUnsafeRawPointeryS2VF(void const * x) SWIFT_NOEXCEPT SWIFT_CALL;
42+
43+
public func passThroughCBool(_ x: CBool) -> CBool { return x }
44+
45+
public func passThroughCChar(_ x: CChar) -> CChar { return x }
46+
public func passThroughCWideChar(_ x: CWideChar) -> CWideChar { return x }
47+
public func passThroughCChar16(_ x: CChar16) -> CChar16 { return x }
48+
public func passThroughCChar32(_ x: CChar32) -> CChar32 { return x }
49+
50+
public func passThroughCSignedChar(_ x: CSignedChar) -> CSignedChar { return x }
51+
public func passThroughCShort(_ x: CShort) -> CShort { return x }
52+
public func passThroughCInt(_ x: CInt) -> CInt { return x }
53+
public func passThroughCLong(_ x: CLong) -> CLong { return x }
54+
public func passThroughCLongLong(_ x: CLongLong) -> CLongLong { return x }
55+
56+
public func passThroughCUnsignedSignedChar(_ x: CUnsignedChar) -> CUnsignedChar { return x }
57+
public func passThroughCUnsignedShort(_ x: CUnsignedShort) -> CUnsignedShort { return x }
58+
public func passThroughCUnsignedInt(_ x: CUnsignedInt) -> CUnsignedInt { return x }
59+
public func passThroughCUnsignedLong(_ x: CUnsignedLong) -> CUnsignedLong { return x }
60+
public func passThroughCUnsignedLongLong(_ x: CUnsignedLongLong) -> CUnsignedLongLong { return x }
61+
62+
public func passThrougCFloat(_ x: CFloat) -> CFloat { return x }
63+
public func passThroughCDouble(_ x: CDouble) -> CDouble { return x }
64+
65+
public func passThroughInt8(_ x: Int8) -> Int8 { return x }
66+
public func passThroughInt16(_ x: Int16) -> Int16 { return x }
67+
public func passThroughInt32(_ x: Int32) -> Int32 { return x }
68+
public func passThroughInt64(_ x: Int64) -> Int64 { return x }
69+
70+
public func passThroughUInt8(_ x: UInt8) -> UInt8 { return x }
71+
public func passThroughUInt16(_ x: UInt16) -> UInt16 { return x }
72+
public func passThroughUInt32(_ x: UInt32) -> UInt32 { return x }
73+
public func passThroughUInt64(_ x: UInt64) -> UInt64 { return x }
74+
75+
public func passThroughFloat(_ x: Float) -> Float { return x }
76+
public func passThroughDouble(_ x: Double) -> Double { return x }
77+
public func passThroughFloat32(_ x: Float32) -> Float32 { return x }
78+
public func passThroughFloat64(_ x: Float64) -> Float64 { return x }
79+
80+
public func passThroughInt(_ x: Int) -> Int { return x }
81+
public func passThroughUInt(_ x: UInt) -> UInt { return x }
82+
public func passThroughBool(_ x: Bool) -> Bool { return x }
83+
84+
public func passThroughOpaquePointer(_ x: OpaquePointer) -> OpaquePointer { return x }
85+
public func passThroughUnsafeRawPointer(_ x: UnsafeRawPointer) -> UnsafeRawPointer { return x }
86+
public func passThroughUnsafeMutableRawPointer(_ x: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { return x }
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend %S/swift-primitive-functions-c-bridging.swift -typecheck -module-name Functions -clang-header-expose-public-decls -emit-clang-header-path %t/functions.h
4+
5+
// RUN: %target-interop-build-clang -c %s -I %t -o %t/swift-functions-execution.o
6+
// RUN: %target-interop-build-swift %S/swift-primitive-functions-c-bridging.swift -o %t/swift-functions-execution -Xlinker %t/swift-functions-execution.o -module-name Functions -Xfrontend -entry-point-function-name -Xfrontend swiftMain
7+
8+
// RUN: %target-codesign %t/swift-functions-execution
9+
// RUN: %target-run %t/swift-functions-execution
10+
11+
// REQUIRES: executable_test
12+
13+
#include <assert.h>
14+
#include "functions.h"
15+
16+
#define VERIFY_PASSTHROUGH_VALUE(function, value) assert(function(value) == (value));
17+
18+
int main() {
19+
// passThroughCBool
20+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughCBoolyS2bF, true);
21+
22+
// passThroughCChar
23+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughCCharys4Int8VADF, 'a');
24+
// passThroughCWideChar
25+
VERIFY_PASSTHROUGH_VALUE($s9Functions20passThroughCWideCharys7UnicodeO6ScalarVAFF, 'a');
26+
// passThroughCChar16
27+
VERIFY_PASSTHROUGH_VALUE($s9Functions18passThroughCChar16ys6UInt16VADF, 0xFE1);
28+
// passThroughCChar32
29+
VERIFY_PASSTHROUGH_VALUE($s9Functions18passThroughCChar32ys7UnicodeO6ScalarVAFF, 0x100FE);
30+
31+
// passThroughCSignedChar
32+
VERIFY_PASSTHROUGH_VALUE($s9Functions22passThroughCSignedCharys4Int8VADF, -1);
33+
// passThroughCShort
34+
VERIFY_PASSTHROUGH_VALUE($s9Functions17passThroughCShortys5Int16VADF, -512);
35+
// passThroughCInt
36+
VERIFY_PASSTHROUGH_VALUE($s9Functions15passThroughCIntys5Int32VADF, -999999);
37+
// passThroughCLong
38+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughCLongyS2iF, -999999);
39+
// passThroughCLongLong
40+
VERIFY_PASSTHROUGH_VALUE($s9Functions20passThroughCLongLongys5Int64VADF, -999998);
41+
42+
// passThroughCUnsignedSignedChar
43+
VERIFY_PASSTHROUGH_VALUE($s9Functions30passThroughCUnsignedSignedCharys5UInt8VADF, 255);
44+
// passThroughCUnsignedShort
45+
VERIFY_PASSTHROUGH_VALUE($s9Functions25passThroughCUnsignedShortys6UInt16VADF, 0xFFFF);
46+
// passThroughCUnsignedInt
47+
VERIFY_PASSTHROUGH_VALUE($s9Functions23passThroughCUnsignedIntys6UInt32VADF, 0xFFFFFFFF);
48+
// passThroughCUnsignedLong
49+
VERIFY_PASSTHROUGH_VALUE($s9Functions24passThroughCUnsignedLongyS2uF, 0xFFFFFFFF);
50+
// passThroughCUnsignedLongLong
51+
VERIFY_PASSTHROUGH_VALUE($s9Functions024passThroughCUnsignedLongE0ys6UInt64VADF, 0xFFFFFFFF);
52+
53+
// passThrougCFloat
54+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThrougCFloatyS2fF, 1.0f);
55+
// passThroughCDouble
56+
VERIFY_PASSTHROUGH_VALUE($s9Functions18passThroughCDoubleyS2dF, 42.125f);
57+
58+
// passThroughInt8
59+
VERIFY_PASSTHROUGH_VALUE($s9Functions15passThroughInt8ys0D0VADF, -1);
60+
// passThroughInt16
61+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughInt16ys0D0VADF, -512);
62+
// passThroughInt32
63+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughInt32ys0D0VADF, -999999);
64+
// passThroughInt64
65+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughInt64ys0D0VADF, -999999999999);
66+
67+
// passThroughUInt8
68+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughUInt8ys0D0VADF, 255);
69+
// passThroughUInt16
70+
VERIFY_PASSTHROUGH_VALUE($s9Functions17passThroughUInt16ys0D0VADF, 0xffff);
71+
// passThroughUInt32
72+
VERIFY_PASSTHROUGH_VALUE($s9Functions17passThroughUInt32ys0D0VADF, 0xffffffff);
73+
// passThroughUInt64
74+
VERIFY_PASSTHROUGH_VALUE($s9Functions17passThroughUInt64ys0D0VADF, 0xffffffffffffffff);
75+
76+
// passThroughFloat
77+
VERIFY_PASSTHROUGH_VALUE($s9Functions16passThroughFloatyS2fF, 1.0f);
78+
// passThroughDouble
79+
VERIFY_PASSTHROUGH_VALUE($s9Functions17passThroughDoubleyS2dF, 42.125f);
80+
// passThroughFloat32
81+
VERIFY_PASSTHROUGH_VALUE($s9Functions18passThroughFloat32yS2fF, 1.0f);
82+
// passThroughFloat64
83+
VERIFY_PASSTHROUGH_VALUE($s9Functions18passThroughFloat64yS2dF, 42.125f);
84+
85+
// passThroughInt
86+
VERIFY_PASSTHROUGH_VALUE($s9Functions14passThroughIntyS2iF, -999997);
87+
// passThroughUInt
88+
VERIFY_PASSTHROUGH_VALUE($s9Functions15passThroughUIntyS2uF, 0xffffffff);
89+
// passThroughBool
90+
VERIFY_PASSTHROUGH_VALUE($s9Functions15passThroughBoolyS2bF, true);
91+
92+
int x = 0;
93+
// passThroughOpaquePointer
94+
VERIFY_PASSTHROUGH_VALUE($s9Functions24passThroughOpaquePointerys0dE0VADF, &x);
95+
// passThroughUnsafeRawPointer
96+
VERIFY_PASSTHROUGH_VALUE($s9Functions27passThroughUnsafeRawPointeryS2VF, &x);
97+
// passThroughUnsafeMutableRawPointer
98+
VERIFY_PASSTHROUGH_VALUE($s9Functions34passThroughUnsafeMutableRawPointeryS2vF, &x);
99+
}

test/Interop/SwiftToC/lit.local.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.suffixes = ['.swift', '.c']

0 commit comments

Comments
 (0)