Warnings -Wsign-compare inside an assert when building with Clang 11.1.0 on Windows #588
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#588
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
The exact problem happens when assert() macro is active; the code location in release 0.8.0 is:
xxhsum.c:1540:38: warning: comparison of integers of different signs: 'const AlgoSelected' and 'unsigned long long' [-Wsign-compare]
assert(0 <= hashType && hashType <= XSUM_TABLE_ELT_SIZE(XSUM_algoName));
This is breaking build of projects using xxHash as in-source dependency, when -Werror flag is active.
Hi @andrzejc, thanks for the report.
Firstly, please let me explain about our status.
At the time of releasing
v0.8.0,-Wall -Wextra. But we didn't have-Werrorin our CI.clang-11.After the release of
v0.8.0,xxhsum.c. But it still has same fuction and condition ofassert().clang-11.0which always test with-Wall -Wextra -Werror.-Wextraincludes-Wsign-compare.So far, we don't have any basic warnings/errors in our
devbranch.Unfortunately, I couldn't reproduce this issue with
clang-11. I tried the following commandsSo, could you provide reproducing procedure of this issue?
Also it'd be great if you can provide actual compiler options. It seems it's hard to track this issue without it.
Lastly, please try recent
devbranch.Hi @t-mat ,
Thank you for quick reply.
This problem doesn't appear with clang-11 on Ubuntu. I was able to get it only on Windows with the official release of Clang from https://github.com/llvm/llvm-project/releases/download/llvmorg-11.1.0/LLVM-11.1.0-win64.exe package. This is also different than the Clang release shipped with mingw64. The way I use xxHash is as a wrap project with meson, so that it is built inline as a part of my project's build. I was asked by meson's maintainer to include link to the issue reported to xxHash in my PR silencing this warning in the meson's wrap project, so that they can remove the workaround if/when the issue is fixed - which is the reason I created this report. My guess is that on Windows, when Clang is using MSVC ABI enum types are signed, which triggers this warning. This is different to Linux Clang build, where it's emulating GCC ABI.
Thanks for the info. I've successfully reproduce this issue with
LLVM-11.1.0-win64.exeonMicrosoft Windows [Version 10.0.19042.1165].For now, I just put the procedure to help other contributors can follow this issue.
Install LLVM-11.1.0-win64
v0.8.0
dev
As for
devbranch, obviously, the most straightforward fix is adding explicit cast fromAlgoSelectedtosize_t.As for
-Wunused-function, we need to check what's happening.If we compile and run above program with
clang.exe(Target: x86_64-pc-windows-msvc) it outputs the followingOf course this output is different from standard Linux version of
clang.So, it seems we need some tweak for
__clang__which doesn't have__GNUC__.Since these warnings/errors/tweaks are hard to find without compiler's help, I think we must include
clangfor MSVC (Target: x86_64-pc-windows-msvc) in our CI.Agreed
It seems there is still a need to add the test target
clang + msvcto either github action (preferably) or Appveyor CI if that's the only working solution ?
Sorry for the delay. I'm working on it. My plan is adding new matrix entries to
windows-visualc-generalofci.yml.Basically, the following
cmakecommand withCMAKE_GENERATOR_TOOLSETenablesclang-cl.But this change also introduces a lot of unnecessary warnings/errors. I'm tweaking
XXHASH_C_FLAGSto minimize it.I just tried to reproduce the
-Wsign-compareissue on my local VM, using Visual Studio 2019 +clang-cl,but failed to witness it.
I'm certain that
assert()is enabled in this test, the main remaining difference I can see isthat my local MSVC version has installed
clang-12.0, instead ofclang-11.1mentioned in this issue.Not yet sure how to play with different
clangversions within MSVC ...edit : VS-install definitely doesn't allow installing multiple versions of
clang, so it's currentlyv12.0or nothing...edit 2 : after following instructions from @t-mat , and installing
clang-11.1on its own (not as part of MSVC) and using it to compilexxhash, I can finally reproduce the reported warning. Gosh, there are so many ways to use and install variants ofclangon the same system, and they also differ in the outcome of their warnings ....Sounds like nightmare or episode from X-Files.
I'll make a free time to find out how we can (or can not) use
clang-clas a vanillaclangor vice versa.Here are some notes for further investigation.
clang-13.0reports same warnings/errors.clang-cl", we can add-v(verbose) option to display actual options forclang. For example-Walltoclang-cl, it translates-Wallto-Weverything.-Walltoclang, we must use/clang:. For exampleclang-cldoesn't report-Wsign-comparewarning even if we give-v /clang:-Wsign-comparetoclang-cldirectly.