Skip to content
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

gh-128902: Fix check for fallthrough attribute support #128903

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

jmroot
Copy link
Contributor

@jmroot jmroot commented Jan 16, 2025

Clang versions prior to 10 (which corresponds to Apple Clang 12) do not support the GCC extension syntax __attribute__((fallthrough)), but do evaluate __has_attribute(fallthrough) to 1 because they support the C++11 style syntax [[fallthrough]]. The only way to tell if the GCC style syntax is supported is thus to check the clang version.

Ref: llvm/llvm-project@1e0affb

Clang versions prior to 10 (which corresponds to Apple Clang 12) do not
support the GCC extension syntax __attribute__((fallthrough)), but do
evaluate __has_attribute(fallthrough) to 1 because they support the
C++11 style syntax [[fallthrough]]. The only way to tell if the GCC
style syntax is supported is thus to check the clang version.

Ref: llvm/llvm-project@1e0affb
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@pablogsal @ambv @ned-deily: I would appreciate if one of you can also review this change, since I don't have access to macOS.

@ned-deily
Copy link
Member

@jmroot Thanks for the PR, as always. On the surface it looks OK to me but I was not successful in creating a failing test environment to check the fix. Following the comment in the PR, I tested with the current HEAD of cpython main (3.14) on macOS 10.14.6 with both the relevant Apple Command Line Tools - LLVM version 10.0.1 (clang-1001.0.46.4) - and then with MacPorts clang version 9.0.1 by removing a _Py_FALLTHROUGH guard and with ./configure --enable-safety to enable -Wimplicit-fallthrough. No fallthrough warnings were generated with either compiler with or without the PR. However, on a current macOS / Xcode configuration (macOS 15.2 / Apple clang version 16.0.0 (clang-1600.0.26.6)), the unguarded fallthrough is warned with or without the PR, as expected. I may be doing something wrong in my testing but it would be good to ensure the comment is accurate. Can you say how this issue arose and how to reproduce?

@jmroot
Copy link
Contributor Author

jmroot commented Jan 21, 2025

Can you say how this issue arose and how to reproduce?

It arose in routine builds of the 3.14 alphas on our buildbots. Here's the first log I found demonstrating the issue: https://build.macports.org/builders/ports-10.9_x86_64-builder/builds/299390/steps/install-port/logs/stdio

I think unknown attributes are supposed to be ignored, so there may be another bug in the mix causing the build failures. It seems pretty clear from the LLVM commit that clang versions less than 10 don't support the attribute, but perhaps only some are harmed by it.

@ned-deily
Copy link
Member

Thanks for the buildbot log which shows the failure when building on macOS 10.9 with the default Command Line Tools for that version. I am able to reproduce the failure on 10.9 and can verify that the PR does fix that failure. So it may be that the comments about particular clang versions are overly restrictive but, given that these older OS and compiler versions are no longer supported upstream and, more importantly, that the fallthrough warnings will show up on builds of the same source with newer compilers, let's not worry about the exact wording.

BTW, while this PR gets past this problem when building on macOS 10.9, there appears to be other build issues using this compiler and SDK on 10.9 (i.e. SSE4.1 instruction set not enabled in Modules/_hacl) that may require you to move to a newer version of clang for 3.14.

@ned-deily ned-deily merged commit edf8033 into python:main Jan 22, 2025
45 checks passed
@vstinner
Copy link
Member

Thanks for your fix @jmroot.

@jmroot jmroot deleted the fallthrough branch January 22, 2025 09:52
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.

3 participants