Skip to content

Commit 4948769

Browse files
committed
[cxx-interop] Import size_t as Int instead of UInt on Linux
When using libc++, Swift imports `size_t` as Int despite `size_t` being an unsigned type. This is intentional & is specified in `lib/ClangImporter/MappedTypes.def`. Previously, MappedTypes were only honored for C/C++ types declared on the file level. In libstdc++, `size_t` is declared within `namespace std` and not on the file level, so the mapping to Int was not applied. This change ensures that MappedTypes are also applied to types declared in `namespace std`.
1 parent 743d82b commit 4948769

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,8 @@ namespace {
27182718
*correctSwiftName);
27192719

27202720
Type SwiftType;
2721-
if (Decl->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
2721+
auto clangDC = Decl->getDeclContext()->getRedeclContext();
2722+
if (clangDC->isTranslationUnit() || clangDC->isStdNamespace()) {
27222723
bool IsError;
27232724
StringRef StdlibTypeName;
27242725
MappedTypeNameKind NameMapping;

test/Interop/Cxx/stdlib/Inputs/fake-toolchain/include/c++/v1/fake-toolchain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ void foo(int x) {}
77

88
}; // namespace FakeNamespace
99

10+
namespace std {
11+
typedef unsigned long size_t;
12+
} // namespace std
13+
1014
#endif

test/Interop/Cxx/stdlib/fake-toolchain-module-interface.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
// CHECK: enum FakeNamespace {
1010
// CHECK: static func foo(_ x: Int32)
1111
// CHECK: }
12+
// CHECK: enum std {
13+
// CHECK: typealias size_t = Int
14+
// CHECK: }
15+

0 commit comments

Comments
 (0)