Skip to content

[cxx-interop] Import size_t as Int instead of UInt on Linux #42003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions benchmark/cxx-source/ReadAccessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ public let benchmarks = [
public func run_ReadAccessor(_ N: Int) {
for i in 0...N {
for j in 0..<100 {
#if os(Linux)
let row = vec![UInt(j)];
#else
let row = vec![j];
#endif
for k in 0..<1_000 {
#if os(Linux)
let element = row[UInt(k)];
#else
let element = row[k];
#endif
blackHole(element)
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,8 @@ namespace {
*correctSwiftName);

Type SwiftType;
if (Decl->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
auto clangDC = Decl->getDeclContext()->getRedeclContext();
if (clangDC->isTranslationUnit() || clangDC->isStdNamespace()) {
bool IsError;
StringRef StdlibTypeName;
MappedTypeNameKind NameMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ void foo(int x) {}

}; // namespace FakeNamespace

namespace std {
typedef unsigned long size_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this get tested on windows? size_t needs unsigned long long for the windows target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be tested on Windows, since Clang on Windows doesn't support -stdlib=libc++ which is used for fake toolchain tests.
There was an effort to support it in Clang, however, the patch got reverted: https://reviews.llvm.org/D101479

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, great

} // namespace std

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
// CHECK: enum FakeNamespace {
// CHECK: static func foo(_ x: Int32)
// CHECK: }
// CHECK: enum std {
// CHECK: typealias size_t = Int
// CHECK: }