Fix fallthrough attribute #575
No reviewers
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash!575
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-fallthrough-attr"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
There're 2 trivial changes
(1) Fix clang version checking.
Only
clang-10and later supports GNU style attribute__attribute__((fallthrough)).Without this change,
CC=clang-9 make clean allfails with the following warning.Please refer the following Clang documentations for
fallthrough.(2) Add
__STDC_VERSION__checking forgcc-11 -std=c90 -pedantic.CC=gcc-11 make clean allreports the following warning as an error.Thanks @t-mat !
Note :
I just made a compilation test after merging this PR on my macos laptop,
using default compiler, which is kind of an apple's special
clang,Apple clang version 11.0.3 (clang-1103.0.32.62),and got the following warning :
I've failed to reproduce the warning with this PR and
clang-11.I could run the following command without error/warning.
My
clang-11isI'll investigate the difference.
I believe that
Apple clangis not the same asclang,especially when it comes to version numbers.
That points to a need to test
macosin CI(which btw is already available on GA : https://github.com/Cyan4973/xxHash/runs/3425515504 ,
but it runs
Apple clang version 12.0.0 (clang-1200.0.32.29))edit : I presume that
Apple clang 11is effectively based onclang-9.In the past, I remember that
Apple clangused to be always in advance compared to regularclang,and +2 versions is what I had kept in mind. Plus, this would match the symptom pretty well.
However, one problem is that
Apple clanghijacks the__clang_major__macro, pretending being version 11 on my laptop.Sorry. Since my macbook has been bricked, I don't use macos nowadays :(
Accoring to Xcode toolchain version history at Wikipedia,
So, we can detect it with the following macro checking?
Yep, that would work.
@Cyan4973 , since GA doesn't provide older version of Apple clang so far, could you add and test version checking for Apple clang?
I'll look for we can add older Apple clang to GA or not.
Sure.
And don't worry for Apple tests on GA.
I'm glad they already exist, existing tests will allow us to detect the most glaring issues specific to
macos.For older versions, I'm not too hopeful either, but well, there is always more to test, we have to accept a few blind spots.
That would solve the issue, but then if the compiler supports C23 standard, there's no need to check specific capabilities using the
has_attribute. that way a user can implement a subset of the new standards to come, without the need for compiler vendors to be fully standard compliant.With that said, I think
__has_[c/cpp]_attributedoesn't work as expected, on MSVC it respect the language standard(-std:)in Clang and probably in GCC it doesn't. so in effect it becomes a general compiler version capability macro. since MSVC does work as expected I believe this feature isn't fully implemented in gcc and clang, that's why we had weird behavior as @t-mat mentioned here : https://github.com/Cyan4973/xxHash/pull/553#issuecomment-899730309If the above is correct, then it's a chaotic scenario since these compilers are already out there.
The optimal solution would probably be to have compilers versions as a initial condition when defining base macros such as INLINE and FALLTHROUGH and not counting on the language standard (as much as we want to).
Theory is fun, in practice is frustrating.