Skip to content

Commit f5d4d48

Browse files
authored
Merge pull request #42003 from apple/egorzhdan/cxx-size_t-libstdcxx
[cxx-interop] Import `size_t` as Int instead of UInt on Linux
2 parents 9e0af17 + 626eadc commit f5d4d48

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

benchmark/cxx-source/ReadAccessor.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,9 @@ public let benchmarks = [
3434
public func run_ReadAccessor(_ N: Int) {
3535
for i in 0...N {
3636
for j in 0..<100 {
37-
#if os(Linux)
38-
let row = vec![UInt(j)];
39-
#else
4037
let row = vec![j];
41-
#endif
4238
for k in 0..<1_000 {
43-
#if os(Linux)
44-
let element = row[UInt(k)];
45-
#else
4639
let element = row[k];
47-
#endif
4840
blackHole(element)
4941
}
5042
}

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)