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

Conversation

egorzhdan
Copy link
Contributor

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.

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Mar 24, 2022
@egorzhdan egorzhdan requested review from hyp and zoecarver March 24, 2022 13:03
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test Linux platform

@@ -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

Copy link
Contributor

@hyp hyp left a comment

Choose a reason for hiding this comment

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

LGTM

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`.
@egorzhdan egorzhdan force-pushed the egorzhdan/cxx-size_t-libstdcxx branch from 4948769 to 626eadc Compare March 24, 2022 15:30
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit f5d4d48 into main Mar 24, 2022
@egorzhdan egorzhdan deleted the egorzhdan/cxx-size_t-libstdcxx branch March 24, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants