Skip to content

Concurrency: silence some -Wcast-function-type-mismatch warnings #78911

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
Jan 28, 2025

Conversation

compnerd
Copy link
Member

The C++ standard does not guarantee that the code and data pointers are interchangeable. Recent enhancements to clang now properly identify the improper reinterpret_cast between function types. Silence the warning by switching to std::bit_cast. Unfortunately, this is a C++20 feature and we are still on C++17. In the case that the compiler doesn't have a bit_cast implementation, fallback with some UB to a local definition.

@compnerd compnerd requested a review from ktoso as a code owner January 25, 2025 07:17
@compnerd
Copy link
Member Author

@swift-ci please test

The C++ standard does not guarantee that the code and data pointers are
interchangeable. Recent enhancements to clang now properly identify the
improper `reinterpret_cast` between function types. Silence the warning
by switching to `std::bit_cast`. Unfortunately, this is a C++20 feature
and we are still on C++17. In the case that the compiler doesn't have a
`bit_cast` implementation, fallback with some UB to a local definition.
@compnerd
Copy link
Member Author

@swift-ci please test

@tshortli
Copy link
Contributor

tshortli commented Jan 26, 2025

Thanks for fixing this! There are many of these warnings, beyond what you fixed here, that we've so far ignored with #pragma clang diagnostic ignored. Perhaps we should centralize the workaround in some shared header so that we can use it everywhere?

@compnerd
Copy link
Member Author

compnerd commented Jan 26, 2025

@tshortli happy to do that if you know of a good place to centralise the definition to. I'd rather do that as a follow up though. This at least pulls all the UB into a single location and we are explicit about this as this covers all of Concurrency and I suspect that we will want this across other modules.

@tshortli
Copy link
Contributor

I don't have a particular place in mind, I'm just making a general observation that it would be nice to not have too many duplicates of this incase someone notices that it needs to be tweaked.

Practically speaking, we probably need one copy of the definition per build that does not share any headers. So one for the compiler, one for the runtime, etc.

None of this is blocking, I'm happy just to have this solved in a reasonably principled way and I can look into extending this to the places where I previously suppressed warnings instead.

@compnerd
Copy link
Member Author

Going to merge this for now. I think that I have an idea for a shared location, but that can be done as a follow up.

@compnerd compnerd merged commit 21841fc into swiftlang:main Jan 28, 2025
5 checks passed
@compnerd compnerd deleted the bitcasting branch January 28, 2025 18:53
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.

2 participants