Skip to content

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Oct 7, 2024

Explanation: __msvc_bit_utils.hpp was added in a recent version of MSVC, and it is causing build errors for SwiftCompilerSources:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:12: error: function '_Select_countr_zero_impl<unsigned long long, (lambda at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:55)>' with deduced return type cannot be used before it is defined
    return _Select_countr_zero_impl<_Common_unsigned>([=](auto _Countr_zero_impl) {

This change references the __msvc_bit_utils.hpp header from the modulemap. Since we still need to support older versions of Visual Studio that do not provide __msvc_bit_utils.hpp, this also teaches ClangImporter to inject an empty header file named __msvc_bit_utils.hpp into the system include directory, unless it already exists.
Scope: ClangImporter logic that injects modulemaps into system headers on Windows was changed, along with the modulemap for Microsoft STL.
Risk: Low, this is a Windows-only change.
Testing: Added a compiler test.
Issue: rdar://137066642
Reviewer: @compnerd @Xazax-hun

Original PR: #76823

`__msvc_bit_utils.hpp` was added in a recent version of MSVC, and it is causing build errors for SwiftCompilerSources:
```
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:12: error: function '_Select_countr_zero_impl<unsigned long long, (lambda at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:55)>' with deduced return type cannot be used before it is defined
    return _Select_countr_zero_impl<_Common_unsigned>([=](auto _Countr_zero_impl) {
```

This change references the `__msvc_bit_utils.hpp` header from the modulemap. Since we still need to support older versions of Visual Studio that do not provide `__msvc_bit_utils.hpp`, this also teaches ClangImporter to inject an empty header file named `__msvc_bit_utils.hpp` into the system include directory, unless it already exists.

rdar://137066642

(cherry picked from commit 16e7cbe)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Oct 7, 2024
@egorzhdan egorzhdan requested a review from a team as a code owner October 7, 2024 11:20
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit 9178511 into release/6.0 Oct 7, 2024
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/6.0-msvc-bit-module branch October 7, 2024 16:58
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.

3 participants