{"id":3165,"date":"2017-07-05T16:51:05","date_gmt":"2017-07-05T05:51:05","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=3165"},"modified":"2017-07-06T11:11:50","modified_gmt":"2017-07-06T00:11:50","slug":"how-we-made-compiler-warnings-fatal-in-firefox","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2017\/07\/05\/how-we-made-compiler-warnings-fatal-in-firefox\/","title":{"rendered":"How we made compiler warnings fatal in Firefox"},"content":{"rendered":"<p>Compiler warnings are mostly good: they identify real problems, and when false positives do occur they are usually easy to work around. However, if they&#8217;re not fatal, they tend to be ignored and build up. (See <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=187528\">bug 187528<\/a> for an idea!)<\/p>\n<p>One way to prevent the build-up is to make them fatal, so they become errors. But won&#8217;t that cause problems? Not if you&#8217;re careful. Here&#8217;s how we did it for Firefox.<\/p>\n<ul>\n<li>Choose with some care which warnings end up fatal. Don&#8217;t be afraid to modify your choices as time goes on.<\/li>\n<li>Introduce a mechanism for enabling fatal warnings on a per-directory basis. Mozilla&#8217;s custom build system used to have a directive called FAIL_ON_WARNINGS for this purpose.<\/li>\n<li>Set things up so that fatal warnings are off by default, but enabled on continuous integration (CI). This means the primary coverage is via CI. You don&#8217;t want fatal warnings on by default because it causes problems for developers who use non-standard compilers (e.g. pre-release versions with new warning classes). Developers using the same compilers as CI can turn it on locally if they want without problem.<\/li>\n<li>Allow per-file exceptions for particular kinds of warnings, because there are occasionally warnings you just want to ignore.<\/li>\n<li>Fix warnings one directory at a time, and turn on fatal warnings for that directory as soon as it&#8217;s warning-free.<\/li>\n<li>Invert the sense of the per-directory mechanism once you&#8217;ve converted more than half of the directories. For Mozilla code we now have the ALLOW_COMPILER_WARNINGS directive. It&#8217;s almost exclusively used for directories containing third-party code which is not under our control.<\/li>\n<li>Gradually expand the coverage of which compilers you have fatal warnings for. Mozilla code now does this for GCC, clang, and MSVC.<\/li>\n<li>Congratulations! You now have fatal warnings on everywhere that is practical.<\/li>\n<\/ul>\n<p>With a setup like this, it&#8217;s possible for a patch to compile on a developer&#8217;s machine but fail to compile on CI. But that&#8217;s just one of many ways in which full CI runs may fail when local runs don&#8217;t. So it&#8217;s not as bad as it seems.<\/p>\n<p>Also, before upgrading the compilers on CI you need to address any new warnings, by fixing them or suppressing them or filing a compiler bug report. But this isn&#8217;t a bad thing.<\/p>\n<p>It took a long time for Firefox to reach this stage, but I think it was worth the effort. Thank you to Chris Peterson and all the others who helped with this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compiler warnings are mostly good: they identify real problems, and when false positives do occur they are usually easy to work around. However, if they&#8217;re not fatal, they tend to be ignored and build up. (See bug 187528 for an idea!) One way to prevent the build-up is to make them fatal, so they become [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/3165"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/comments?post=3165"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/3165\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=3165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=3165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=3165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}