Skip to content

Various cleanups#1570

Open
YexuanXiao wants to merge 4 commits into
microsoft:masterfrom
YexuanXiao:clean-unsafe-cast-upstream
Open

Various cleanups#1570
YexuanXiao wants to merge 4 commits into
microsoft:masterfrom
YexuanXiao:clean-unsafe-cast-upstream

Conversation

@YexuanXiao
Copy link
Copy Markdown
Contributor

@YexuanXiao YexuanXiao commented Apr 17, 2026

  • Replace unsafe C-style casts with reinterpret_cast and merge some into abi_cast and abi_t_abi_cast.
  • Use __builtin_bit_cast to avoid strict aliasing violations and eliminate GCC warnings (supported by GCC, Clang, and MSVC post-2020 as underlying intrinsic of C++20 std::bit_cast). Fixes Bug: GCC warns about breaking strict-aliasing rules for 32-bit builds #1568.
  • Simplify interlocked_read_pointer.

If C++/WinRT decide to discontinue support for C++17, it can use std::bit_cast instead of __builtin_bit_cast, and use std::atomic_ref instead of interlocked_read_pointer and other raw synchronization intrinsics.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 many get_abi/shim call sites to use them.
  • Reworks factory_cache_entry_base::clear() to use __builtin_bit_cast when performing 64/128-bit CAS to avoid strict-aliasing warnings.
  • Simplifies interlocked_read_pointer and 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.

Comment thread strings/base_array.h Outdated
Comment thread strings/base_windows.h
Comment thread strings/base_windows.h
Comment thread strings/base_windows.h
Comment thread strings/base_activation.h Outdated
Comment thread strings/base_activation.h
@YexuanXiao YexuanXiao requested a review from Copilot May 22, 2026 05:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: GCC warns about breaking strict-aliasing rules for 32-bit builds

2 participants