[LLVMdev] Enabling stricter warnings for Windows builds

Kaylor, Andrew andrew.kaylor at intel.com
Fri Mar 20 16:26:54 PDT 2015


I've been guilty several times recently of committing code that introduced build warnings.  It's a poor excuse, but my excuse is that I've been working on code for Windows and LLVM doesn't enable strict warnings by default on Windows and produces nearly half a million warnings (literally) if you manually turn them on.  As such, I thought I'd make an effort to see what it would take to clean things up on Windows.

Looking just at the main llvm project I found that despite the multitude of warnings, there were only 16 unique warnings being produced.  I see in HandleLLVMOptions.cmake that there are already 17 warnings being explicitly disabled, so I thought it would be reasonable to start by adding most of the warnings that are currently being produced to that list.

I triaged the warnings that I was seeing according to how certain I was that disabling them was a reasonable thing to do.  Here's what I came up with (with a glaring bias toward just disabling common warnings and fixing uncommon ones):


Warnings that should almost certainly be disabled
-------------------------------------------------------------
warning C4100: unreferenced formal parameter (263666 times)
warning C4127: conditional expression is constant (101120 times)
warning C4512: assignment operator could not be generated (40472 times)
warning C4505: unreferenced local function has been removed (6606 times)
warning C4610: [...] can never be instantiated (1714 times)
warning C4510: default constructor could not be generated (1714 times)
warning C4702: unreachable code (1343 times)
warning C4706: assignment within conditional expression (296 times)


Warnings that seem like they should be fixed but will take a little time to correct
--------------------------------------------------------------------------------------------------
warning C4245: signed/unsigned mismatch (962 times)
warning C4310: cast truncates constant value (216 times)
warning C4701: potentially uninitialized local variable (123 times)
warning C4703: potentially uninitialized local pointer variable (40 times)
warning C4389: signed/unsigned mismatch (28 times)


Warnings that should probably be fixed
-------------------------------------------------
warning C4189: local variable is initialized but not referenced (6 times)
warning C4204: nonstandard extension used : non-constant aggregate initializer (4 times)
warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable (2 times)


As a caveat, I didn't look at the code for any of these warnings -- not one -- so I don't know anything about how benign any of them might be.  I also don't know why there are two different "signed/unsigned mismatch" warnings (though I'm guessing one is assignments and the other is comparisons).

I have a local build going right now with the first two groups of warnings disabled.  If it goes as expected, I'd like to commit this change along with fixes for the very small last group.  Then, after a reasonable adjustment period to let subprojects see how this looks, I'd like to turn on the "all warnings" option by default for Windows builds.

Does anyone see any problems with the way I have categorized these warnings?

Thanks,
Andy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150320/935264c5/attachment.html>


More information about the llvm-dev mailing list