Various cleanups#1570
Open
YexuanXiao wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR performs a set of internal header cleanups in the C++/WinRT projection, primarily refactoring ABI access patterns (replacing C-style casts), addressing strict-aliasing warnings (notably on GCC x86), and simplifying some low-level interlocked helpers. It also updates the code generator to emit the new ABI-cast helpers.
Changes:
- Introduces shared ABI cast helpers (
impl::abi_cast,impl::abi_t_abi_cast) and updates manyget_abi/shim call sites to use them. - Reworks
factory_cache_entry_base::clear()to use__builtin_bit_castwhen performing 64/128-bit CAS to avoid strict-aliasing warnings. - Simplifies
interlocked_read_pointerand updates code generation templates to match the new ABI-cast helpers.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| strings/base_windows.h | Adds impl::abi_cast and refactors ABI shims/calls to use new helpers. |
| strings/base_string.h | Switches hstring ABI helpers to impl::abi_cast. |
| strings/base_string_input.h | Updates param::hstring ABI access to impl::abi_cast. |
| strings/base_reference_produce.h | Replaces C-style cast in unbox_value_or default path with reinterpret_cast. |
| strings/base_natvis.h | Replaces C-style casts with reinterpret_cast for natvis inspection helpers. |
| strings/base_meta.h | Adds impl::abi_t_abi_cast helper for ABI-vtable access. |
| strings/base_macros.h | Updates WINRT_IMPL_SHIM macro to use impl::abi_t_abi_cast. |
| strings/base_implements.h | Replaces C-style casts with reinterpret_cast in producer conversion helpers. |
| strings/base_events.h | Updates event revoker teardown to use impl::abi_t_abi_cast. |
| strings/base_delegate.h | Replaces C-style cast with reinterpret_cast in delegate invocation. |
| strings/base_coroutine_foundation.h | Updates when_any completion handler ABI access and interlocked exchange usage. |
| strings/base_collections_input_vector.h | Updates collection param ABI extraction to impl::abi_cast. |
| strings/base_collections_input_vector_view.h | Updates collection param ABI extraction to impl::abi_cast. |
| strings/base_collections_input_map.h | Updates collection param ABI extraction to impl::abi_cast. |
| strings/base_collections_input_map_view.h | Updates collection param ABI extraction to impl::abi_cast. |
| strings/base_collections_input_iterable.h | Updates collection param ABI extraction to impl::abi_cast. |
| strings/base_array.h | Refactors array_view ABI extraction and inspectable helper calls to use impl::abi_cast. |
| strings/base_agile_ref.h | Minor preprocessor formatting cleanup for defined(...). |
| strings/base_activation.h | Simplifies interlocked_read_pointer, adds __builtin_bit_cast for CAS, updates activation factory ABI calls. |
| cppwinrt/code_writers.h | Updates generated code templates to emit impl::abi_cast / impl::abi_t_abi_cast. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
reinterpret_castand merge some intoabi_castandabi_t_abi_cast.__builtin_bit_castto avoid strict aliasing violations and eliminate GCC warnings (supported by GCC, Clang, and MSVC post-2020 as underlying intrinsic of C++20std::bit_cast). Fixes Bug: GCC warns about breaking strict-aliasing rules for 32-bit builds #1568.interlocked_read_pointer.If C++/WinRT decide to discontinue support for C++17, it can use
std::bit_castinstead of__builtin_bit_cast, and usestd::atomic_refinstead ofinterlocked_read_pointerand other raw synchronization intrinsics.