Skip to content

Commit c7265f3

Browse files
committed
fix the macos tests
1 parent bc893d7 commit c7265f3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,24 @@ getKnownTypeInfo(const TypeDecl *typeDecl, PrimitiveTypeMapping &typeMapping,
3939
: typeMapping.getKnownCTypeInfo(typeDecl);
4040
}
4141

42-
bool isKnownCxxType(Type t, PrimitiveTypeMapping &typeMapping) {
42+
bool isKnownType(Type t, PrimitiveTypeMapping &typeMapping,
43+
OutputLanguageMode languageMode) {
4344
const TypeDecl *typeDecl;
4445
if (auto *typeAliasType = dyn_cast<TypeAliasType>(t.getPointer()))
4546
typeDecl = typeAliasType->getDecl();
4647
else if (auto *structDecl = t->getStructOrBoundGenericStruct())
4748
typeDecl = structDecl;
4849
else
4950
return false;
50-
return getKnownTypeInfo(typeDecl, typeMapping, OutputLanguageMode::Cxx) !=
51-
None;
51+
return getKnownTypeInfo(typeDecl, typeMapping, languageMode) != None;
52+
}
53+
54+
bool isKnownCxxType(Type t, PrimitiveTypeMapping &typeMapping) {
55+
return isKnownType(t, typeMapping, OutputLanguageMode::Cxx);
56+
}
57+
58+
bool isKnownCType(Type t, PrimitiveTypeMapping &typeMapping) {
59+
return isKnownType(t, typeMapping, OutputLanguageMode::ObjC);
5260
}
5361

5462
// Prints types in the C function signature that corresponds to the
@@ -164,6 +172,7 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
164172
// Print out the return type.
165173
bool isIndirectReturnType =
166174
kind == FunctionSignatureKind::CFunctionProto &&
175+
!isKnownCType(resultTy, typeMapping) &&
167176
interopContext.getIrABIDetails().shouldReturnIndirectly(resultTy);
168177
if (!isIndirectReturnType) {
169178
OptionalTypeKind retKind;

test/Interop/SwiftToC/structs/small-structs-pass-return-direct-in-c.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ public func printStructI8AndU32AndI16(_ x: StructI8AndU32AndI16) {
136136

137137
// CHECK: static inline void swift_interop_returnDirect_Structs_StructU16AndPointer(char * _Nonnull result, struct swift_interop_stub_Structs_StructU16AndPointer value) __attribute__((always_inline)) {
138138
// CHECK-NEXT: memcpy(result + 0, &value._1, 1);
139-
// CHECK-NEXT: memcpy(result + 8, &value._2, 8);
139+
// CHECK-NEXT: memcpy(result + [[PTRSIZE:[48]]], &value._2, [[PTRSIZE]]);
140140
// CHECK-NEXT: }
141141

142142
// CHECK: static inline struct swift_interop_stub_Structs_StructU16AndPointer swift_interop_passDirect_Structs_StructU16AndPointer(const char * _Nonnull value) __attribute__((always_inline)) {
143143
// CHECK-NEXT: struct swift_interop_stub_Structs_StructU16AndPointer result;
144144
// CHECK-NEXT: memcpy(&result._1, value + 0, 1);
145-
// CHECK-NEXT: memcpy(&result._2, value + 8, 8);
145+
// CHECK-NEXT: memcpy(&result._2, value + [[PTRSIZE]], [[PTRSIZE]]);
146146
// CHECK-NEXT: return result;
147147
// CHECK-NEXT: }
148148

0 commit comments

Comments
 (0)