Miscellaneous warnings in code using Visual Studio

When I build on Windows 7 with Visual Studio, I get various warnings that were ignored until I recently set

LLVM_ENABLE_WERROR:BOOL=ON

One example is shown below. Should I take the time to hunt these down and fix them?

If they prove to be good cleanup/improvements to the code in general - but we don’t try too hard to be -Werror clean on every compiler, mostly just self-hosted clang. The line is fuzzy - if a warning isn’t /too/ bad (ie: doesn’t require extreme contortions to the code to address the warning) then fixing instances seems ok. If it’s unhelpful (eg: a warning has a high false positive rate and/or clang’s equivalent warning is more nuanced and avoids the need to touch false positives) we may disable warnings in LLVM. (this doesn’t address the issue of warnings in LLVM’s public headers - not every downstream consumer of LLVM is going to disable the same set of warnings, so sometimes it’s necessary to do some warning cleanup even for undesirable warnings)

The problem with not fixing them is that I cannot enable WERROR. So warnings in my own code might zoom by unseen and then bust the build, as happened the other day. Of course, it's possible that warning was one produced by the build's compiler but not by Visual Studio's.

I could always enable it just for a build of my code, then disable it again.

If they prove to be good cleanup/improvements to the code in general - but we don't try too hard to be -Werror clean on every compiler, mostly just self-hosted clang.

This doesn't match my understanding -- we have a documented CMake
option that controls -Werror and I think we've always tried to be
-Werror clean with Clang, GCC, and MSVC builds before to support that
build configuration.

The line is fuzzy - if a warning isn't /too/ bad (ie: doesn't require extreme contortions to the code to address the warning) then fixing instances seems ok. If it's unhelpful (eg: a warning has a high false positive rate and/or clang's equivalent warning is more nuanced and avoids the need to touch false positives) we may disable warnings in LLVM. (this doesn't address the issue of warnings in LLVM's public headers - not every downstream consumer of LLVM is going to disable the same set of warnings, so sometimes it's necessary to do some warning cleanup even for undesirable warnings)

I agree that we don't want large amounts of code churn for warnings
that are typically off by default in our default cmake configuration
(or could be made off by default if they're sufficiently low quality),
but I think this situation is different. I think these new warnings
were recently introduced and are ones we would typically fix with an
NFC patch.

~Aaron

Yep, it’s a tradeoff to be sure. I’d recommend, if possible, self-hosting (using clang to build your development clang) - but otherwise, yes, fixes to other compiler warnings are welcome but in some cases it may be desirable to disable a warning instead (& realize this kind of thing will regress easily due to other people’s contributions since they aren’t using MSVC).

If they prove to be good cleanup/improvements to the code in general - but we don’t try too hard to be -Werror clean on every compiler, mostly just self-hosted clang.

This doesn’t match my understanding – we have a documented CMake
option that controls -Werror and I think we’ve always tried to be
-Werror clean with Clang, GCC, and MSVC builds before to support that
build configuration.

Certainly I don’t think we’ve ever outright rejected any path forward for avoiding a warning from any supported compiler (either by changing the code or suppressing the warning in the LLVM build in general) - though I don’t think practically speaking we try very hard to keep all the supported compiler versions (not just brands, but the full supported version range of each) -Werror clean - about the cleanest would be a selfhost build, there are many buildbots/etc that check that is -Werror clean.

>
> If they prove to be good cleanup/improvements to the code in general - but we don't try too hard to be -Werror clean on every compiler, mostly just self-hosted clang.

This doesn't match my understanding -- we have a documented CMake
option that controls -Werror and I think we've always tried to be
-Werror clean with Clang, GCC, and MSVC builds before to support that
build configuration.

Certainly I don't think we've ever outright rejected any path forward for avoiding a warning from any supported compiler (either by changing the code or suppressing the warning in the LLVM build in general) - though I don't think practically speaking we try very hard to keep all the supported compiler versions (not just brands, but the full supported version range of each) -Werror clean - about the cleanest would be a selfhost build, there are many buildbots/etc that check that is -Werror clean.

My recollection is that we only require the selfhost build to be
-Werror clean (with a bot configured to test that) but that we strive
to be -Werror clean when it won't introduce unwanted changes to the
code (in which case, we're happier to disable the warning within
CMake). So I think we may be saying the same things with different
words, but maybe we have a different definition of "try very hard"
here. :slight_smile:

~Aaron

If they prove to be good cleanup/improvements to the code in general - but we don’t try too hard to be -Werror clean on every compiler, mostly just self-hosted clang.

This doesn’t match my understanding – we have a documented CMake
option that controls -Werror and I think we’ve always tried to be
-Werror clean with Clang, GCC, and MSVC builds before to support that
build configuration.

Certainly I don’t think we’ve ever outright rejected any path forward for avoiding a warning from any supported compiler (either by changing the code or suppressing the warning in the LLVM build in general) - though I don’t think practically speaking we try very hard to keep all the supported compiler versions (not just brands, but the full supported version range of each) -Werror clean - about the cleanest would be a selfhost build, there are many buildbots/etc that check that is -Werror clean.

My recollection is that we only require the selfhost build to be
-Werror clean (with a bot configured to test that) but that we strive
to be -Werror clean when it won’t introduce unwanted changes to the
code (in which case, we’re happier to disable the warning within
CMake). So I think we may be saying the same things with different
words, but maybe we have a different definition of “try very hard”
here. :slight_smile:

Yep yep. Sounds roughly similar

As a fellow Visual Studio user, I feel your pain. However, trying to fix these warnings is a losing battle. Most LLVM developers do not use Visual Studio, so my experience tells me that new warnings will be added faster than you can fix them. This is not a indictment of the community; it's just that there are so many compilers out there and they all have different warnings. Being werror clean across compilers is just not manageable.

As the code owner of tablegen, it may be worth it to get your bit of the codebase close to being werror clean just for your personal productivity. I don't know how hard that would be, some parts of the codebase are pretty gross in MSVC.

Thanks,
   Christopher Tetreault

Yeah, periodically I contemplate doing some patches to reduce the noise
from MSVC, but the annoyance has never risen to the level of deciding
to act on it.
There is one module whose contents are completely conditionalized out
on Windows, but I think that produces a linker warning rather than a
compiler warning, so I wouldn't expect Werror to turn that into a hard
error.
--paulr

In LLDB, we’ve been moderately aggressive at fixing warnings for MSVC.

The particular example given (assert(uint16_t + uint16_t >= size_t)) is almost certainly harmless, especially since it’s in an assertion.

I have, however, spent a lot of time chasing bugs (in other projects) that could have been found immediately by enabling signed/unsigned comparison warnings. As a result, I’m particularly uncomfortable ignoring those. I’ve developed fluency in the integral conversion rules, but I’m not sure every C++ programmer would immediately recognize where the signed value arises given that the expression involves three unsigned values. And it’s exactly those kinds of implicit conversions that lead to surprising bugs, and it’s why it’s a reasonable warning to pay attention to.

I've had similar issues with warnings from LLVM headers with Visual Studio.
The way I've dealt with this is this to use the experimental /external compiler flags within Visual Studio which allow control of warning levels from external headers.

For example adding these flags will set warning level to W0 for all include files that are included with angle brackets:

/experimental:external /external:anglebrackets /external:W0

This is a bit crude because you can't target specific libraries, but it might still be helpful depending on your application.

Regards,

Machiel van Hooren