That looks interesting and definitely near to what is breaking in my stdlib.
The only thing is I'm compiling very simple linux style C code, which doesn't have fancy types like CUnsignedInt, just types like "unsigned short", which I understand to be pretty much standard c compiler intrinsic in all reasonable compilers, rather than fancy aliases.
Unfortunately I'm in work at the moment and can't post my C code here. I'll do another post tonight with the functions that are not importing.
In the meantime, another thought...
The ClangImporter has this macro in MappedTypes.def that looks like it might be involved in the interpretation of C code type imports...
#define MAP_STDLIB_TYPE(C_TYPE_NAME, C_TYPE_KIND, C_TYPE_BITWIDTH, \
SWIFT_TYPE_NAME, CAN_BE_MISSING, \
C_NAME_MAPPING) \
MAP_TYPE(C_TYPE_NAME, C_TYPE_KIND, C_TYPE_BITWIDTH, \
"Swift", SWIFT_TYPE_NAME, CAN_BE_MISSING, \
C_NAME_MAPPING)
// MacTypes.h defines typedefs UIntXX, SIntXX, FloatXX.
MAP_STDLIB_TYPE("UInt8", UnsignedInt, 8, "UInt8", false, DoNothing)
MAP_STDLIB_TYPE("UInt16", UnsignedInt, 16, "UInt16", false, DoNothing)
MAP_STDLIB_TYPE("UInt32", UnsignedInt, 32, "UInt32", false, DoNothing)
MAP_STDLIB_TYPE("UInt64", UnsignedInt, 64, "UInt64", false, DoNothing)
This is then used in getSwiftStdlibType, which looks like it might be the system that reads types from C and finds their matching type in stdlib
static std::pair<Type, StringRef>
getSwiftStdlibType(const clang::TypedefNameDecl *D,
Identifier Name,
ClangImporter::Implementation &Impl,
bool *IsError, MappedTypeNameKind &NameMapping) {
*IsError = false;
MappedCTypeKind CTypeKind;
unsigned Bitwidth;
StringRef SwiftModuleName;
bool IsSwiftModule; // True if SwiftModuleName == STDLIB_NAME.
StringRef SwiftTypeName;
bool CanBeMissing;
do {
#define MAP_TYPE(C_TYPE_NAME, C_TYPE_KIND, C_TYPE_BITWIDTH, \
SWIFT_MODULE_NAME, SWIFT_TYPE_NAME, \
CAN_BE_MISSING, C_NAME_MAPPING) \
if (Name.str() == C_TYPE_NAME) { \
CTypeKind = MappedCTypeKind::C_TYPE_KIND; \
Bitwidth = C_TYPE_BITWIDTH; \
if (StringRef(SWIFT_MODULE_NAME) == StringRef(STDLIB_NAME)) \
IsSwiftModule = true; \
else { \
IsSwiftModule = false; \
SwiftModuleName = SWIFT_MODULE_NAME; \
} \
SwiftTypeName = SWIFT_TYPE_NAME; \
CanBeMissing = CAN_BE_MISSING; \
NameMapping = MappedTypeNameKind::C_NAME_MAPPING; \
assert(verifyNameMapping(MappedTypeNameKind::C_NAME_MAPPING, \
C_TYPE_NAME, SWIFT_TYPE_NAME) && \
"MappedTypes.def: Identical names must use DoNothing"); \
break; \
}
#include "MappedTypes.def"
// We did not find this type, thus it is not mapped.
return std::make_pair(Type(), "");
} while (0);
clang::ASTContext &ClangCtx = Impl.getClangASTContext();
auto ClangType = D->getUnderlyingType();
I ran swift in the debugger and put a breakpoint on getSwiftStdlibType
to find out why the types are not being picked up, but the breakpoint is not being hit!
I've confirmed that other breakpoints on the executable (e.g. main) are being hit so lldb is working fine but it seems this code is not being hit.
I'm not sure where to look now?