2016-08-05 10:07:18 +03:00
|
|
|
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
|
|
|
# vim: set filetype=python:
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2020-10-08 07:07:46 +03:00
|
|
|
option(
|
|
|
|
"--enable-warnings-as-errors",
|
|
|
|
env="MOZ_ENABLE_WARNINGS_AS_ERRORS",
|
|
|
|
default=depends("MOZ_AUTOMATION")(lambda x: bool(x)),
|
|
|
|
help="{Enable|Disable} treating warnings as errors",
|
|
|
|
)
|
2016-08-05 10:07:18 +03:00
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
|
2018-12-14 14:34:15 +03:00
|
|
|
@depends("--enable-warnings-as-errors")
|
|
|
|
def rust_warning_flags(warnings_as_errors):
|
|
|
|
flags = []
|
|
|
|
|
|
|
|
# Note that cargo passes --cap-lints warn to rustc for third-party code, so
|
|
|
|
# we don't need a very complicated setup.
|
|
|
|
if warnings_as_errors:
|
|
|
|
flags.append("-Dwarnings")
|
2019-05-22 15:59:01 +03:00
|
|
|
else:
|
|
|
|
flags.extend(("--cap-lints", "warn"))
|
2018-12-14 14:34:15 +03:00
|
|
|
|
|
|
|
return flags
|
|
|
|
|
2019-09-26 00:30:38 +03:00
|
|
|
|
|
|
|
c_warning_flag = dependable("-Werror")
|
|
|
|
|
2020-10-26 21:34:53 +03:00
|
|
|
|
2019-09-26 00:30:38 +03:00
|
|
|
@depends("--enable-warnings-as-errors", c_warning_flag)
|
|
|
|
def warnings_as_errors(warnings_as_errors, c_warning_flag):
|
|
|
|
if not warnings_as_errors:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return c_warning_flag
|
|
|
|
|
2020-10-26 21:34:53 +03:00
|
|
|
|
2019-09-26 00:30:38 +03:00
|
|
|
set_config("WARNINGS_AS_ERRORS", warnings_as_errors)
|
|
|
|
# We have a peculiar setup in old-configure.in where some compilation tests
|
|
|
|
# depend on enabling warnings-as-errors even if it's disabled for Firefox
|
|
|
|
# compilation. We therefore need this assignment.
|
|
|
|
add_old_configure_assignment("WARNINGS_AS_ERRORS", c_warning_flag)
|
|
|
|
|
2018-12-14 14:34:15 +03:00
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# GCC/Clang warnings:
|
2018-11-27 05:01:48 +03:00
|
|
|
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
|
|
|
|
# https://clang.llvm.org/docs/DiagnosticsReference.html
|
2016-08-05 11:13:48 +03:00
|
|
|
|
|
|
|
# lots of useful warnings
|
|
|
|
add_gcc_warning("-Wall")
|
|
|
|
|
2018-11-27 05:01:48 +03:00
|
|
|
# catch implicit truncation of enum values assigned to smaller bit fields
|
|
|
|
check_and_add_gcc_warning("-Wbitfield-enum-conversion")
|
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# catches bugs, e.g. "if (c); foo();", few false positives
|
|
|
|
add_gcc_warning("-Wempty-body")
|
|
|
|
|
|
|
|
# catches return types with qualifiers like const
|
|
|
|
add_gcc_warning("-Wignored-qualifiers")
|
|
|
|
|
2021-01-12 17:18:22 +03:00
|
|
|
# function declaration hides virtual function from base class.
|
|
|
|
# Don't enable for GCC, since it's more strict than clang,
|
|
|
|
# and the additional cases it covers are not valuable.
|
|
|
|
add_gcc_warning(
|
|
|
|
"-Woverloaded-virtual",
|
|
|
|
cxx_compiler,
|
|
|
|
when=depends(cxx_compiler)(lambda c: c.type != "gcc"),
|
|
|
|
)
|
2016-08-05 11:13:48 +03:00
|
|
|
|
|
|
|
# catches pointer arithmetic using NULL or sizeof(void)
|
|
|
|
add_gcc_warning("-Wpointer-arith")
|
|
|
|
|
2018-08-20 20:10:57 +03:00
|
|
|
# catch modifying constructor parameter that shadows member variable
|
|
|
|
check_and_add_gcc_warning("-Wshadow-field-in-constructor-modified")
|
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# catches comparing signed/unsigned ints
|
|
|
|
add_gcc_warning("-Wsign-compare")
|
|
|
|
|
|
|
|
# catches overflow bugs, few false positives
|
|
|
|
add_gcc_warning("-Wtype-limits")
|
|
|
|
|
|
|
|
# catches some dead code
|
|
|
|
add_gcc_warning("-Wunreachable-code")
|
2017-08-09 09:12:41 +03:00
|
|
|
check_and_add_gcc_warning("-Wunreachable-code-return")
|
2016-08-05 11:13:48 +03:00
|
|
|
|
|
|
|
# catches treating string literals as non-const
|
|
|
|
add_gcc_warning("-Wwrite-strings", cxx_compiler)
|
|
|
|
|
|
|
|
# turned on by -Wall, but we use offsetof on non-POD types frequently
|
|
|
|
add_gcc_warning("-Wno-invalid-offsetof", cxx_compiler)
|
|
|
|
|
|
|
|
# catches objects passed by value to variadic functions.
|
|
|
|
check_and_add_gcc_warning("-Wclass-varargs")
|
|
|
|
|
2019-12-12 05:18:37 +03:00
|
|
|
# catches empty if/switch/for initialization statements that have no effect
|
|
|
|
check_and_add_gcc_warning("-Wempty-init-stmt", cxx_compiler)
|
|
|
|
|
2018-08-15 09:03:52 +03:00
|
|
|
# catches some implicit conversion of floats to ints
|
|
|
|
check_and_add_gcc_warning("-Wfloat-overflow-conversion")
|
|
|
|
check_and_add_gcc_warning("-Wfloat-zero-conversion")
|
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# catches issues around loops
|
|
|
|
check_and_add_gcc_warning("-Wloop-analysis")
|
2021-01-11 18:30:45 +03:00
|
|
|
# But, disable range-loop-analysis because it can raise unhelpful false
|
|
|
|
# positives.
|
|
|
|
check_and_add_gcc_warning("-Wno-range-loop-analysis")
|
2016-08-05 11:13:48 +03:00
|
|
|
|
|
|
|
# catches C++ version forward-compat issues
|
2018-08-15 20:02:07 +03:00
|
|
|
check_and_add_gcc_warning("-Wc++2a-compat", cxx_compiler)
|
2016-08-05 11:13:48 +03:00
|
|
|
|
2017-04-08 22:36:48 +03:00
|
|
|
# catches possible misuse of the comma operator
|
|
|
|
check_and_add_gcc_warning("-Wcomma", cxx_compiler)
|
|
|
|
|
2017-10-06 09:14:02 +03:00
|
|
|
# catches duplicated conditions in if-else-if chains
|
|
|
|
check_and_add_gcc_warning("-Wduplicated-cond")
|
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# catches unintentional switch case fallthroughs
|
|
|
|
check_and_add_gcc_warning("-Wimplicit-fallthrough", cxx_compiler)
|
|
|
|
|
2020-02-04 17:36:58 +03:00
|
|
|
# catches unused variable/function declarations
|
|
|
|
check_and_add_gcc_warning("-Wunused-function", cxx_compiler)
|
|
|
|
check_and_add_gcc_warning("-Wunused-variable", cxx_compiler)
|
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# catches expressions used as a null pointer constant
|
|
|
|
# XXX: at the time of writing, the version of clang used on the OS X test
|
|
|
|
# machines has a bug that causes it to reject some valid files if both
|
|
|
|
# -Wnon-literal-null-conversion and -Wsometimes-uninitialized are
|
|
|
|
# specified. We work around this by instead using
|
|
|
|
# -Werror=non-literal-null-conversion, but we only do that when
|
|
|
|
# --enable-warnings-as-errors is specified so that no unexpected fatal
|
|
|
|
# warnings are produced.
|
|
|
|
check_and_add_gcc_warning(
|
|
|
|
"-Werror=non-literal-null-conversion", when="--enable-warnings-as-errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
# catches string literals used in boolean expressions
|
|
|
|
check_and_add_gcc_warning("-Wstring-conversion")
|
|
|
|
|
2018-10-16 08:49:15 +03:00
|
|
|
# catches comparisons that are always true or false
|
2018-08-15 08:39:03 +03:00
|
|
|
check_and_add_gcc_warning("-Wtautological-overlap-compare")
|
2018-10-16 08:49:15 +03:00
|
|
|
check_and_add_gcc_warning("-Wtautological-unsigned-enum-zero-compare")
|
|
|
|
check_and_add_gcc_warning("-Wtautological-unsigned-zero-compare")
|
2019-08-21 18:32:26 +03:00
|
|
|
# This can be triggered by certain patterns used deliberately in portable code
|
|
|
|
check_and_add_gcc_warning("-Wno-error=tautological-type-limit-compare")
|
2018-08-15 08:39:03 +03:00
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# we inline 'new' and 'delete' in mozalloc
|
|
|
|
check_and_add_gcc_warning("-Wno-inline-new-delete", cxx_compiler)
|
|
|
|
|
|
|
|
# Prevent the following GCC warnings from being treated as errors:
|
|
|
|
# too many false positives
|
|
|
|
check_and_add_gcc_warning("-Wno-error=maybe-uninitialized")
|
|
|
|
|
|
|
|
# we don't want our builds held hostage when a platform-specific API
|
|
|
|
# becomes deprecated.
|
|
|
|
check_and_add_gcc_warning("-Wno-error=deprecated-declarations")
|
|
|
|
|
|
|
|
# false positives depending on optimization
|
|
|
|
check_and_add_gcc_warning("-Wno-error=array-bounds")
|
|
|
|
|
|
|
|
# can't get rid of those PGO warnings
|
2019-03-19 02:52:22 +03:00
|
|
|
check_and_add_gcc_warning("-Wno-error=coverage-mismatch")
|
|
|
|
|
|
|
|
# -Wbackend-plugin warnings from Android PGO profile-use builds:
|
|
|
|
# error: /builds/worker/workspace/build/src/mozglue/misc/AutoProfilerLabel.cpp:
|
|
|
|
# Function control flow change detected (hash mismatch)
|
|
|
|
# _ZN7mozilla17AutoProfilerLabelD2Ev [-Werror,-Wbackend-plugin]
|
|
|
|
check_and_add_gcc_warning("-Wno-error=backend-plugin")
|
2016-08-05 11:13:48 +03:00
|
|
|
|
2017-05-31 00:19:38 +03:00
|
|
|
# false positives depending on optimizations
|
|
|
|
check_and_add_gcc_warning("-Wno-error=free-nonheap-object")
|
2016-08-05 11:13:48 +03:00
|
|
|
|
2018-03-13 15:45:59 +03:00
|
|
|
# Would be a pain to fix all occurrences, for very little gain
|
2020-01-13 17:54:39 +03:00
|
|
|
check_and_add_gcc_warning("-Wno-multistatement-macros")
|
2018-03-13 15:45:59 +03:00
|
|
|
|
2018-05-12 13:00:39 +03:00
|
|
|
# Disable the -Werror for return-std-move because of a false positive
|
|
|
|
# on nsTAutoStringN: https://bugs.llvm.org/show_bug.cgi?id=37249
|
|
|
|
check_and_add_gcc_warning("-Wno-error=return-std-move")
|
|
|
|
|
2018-05-28 15:56:41 +03:00
|
|
|
# Disable the -Werror for -Wclass-memaccess as we have a long
|
|
|
|
# tail of issues to fix
|
|
|
|
check_and_add_gcc_warning("-Wno-error=class-memaccess")
|
|
|
|
|
2018-09-20 05:05:24 +03:00
|
|
|
# -Watomic-alignment is a new warning in clang 7 that seems way too broad.
|
|
|
|
# https://bugs.llvm.org/show_bug.cgi?id=38593
|
|
|
|
check_and_add_gcc_warning("-Wno-error=atomic-alignment")
|
|
|
|
|
2019-02-04 17:32:13 +03:00
|
|
|
# New warning with gcc 9. Not useful
|
|
|
|
# https://bugzilla.mozilla.org/show_bug.cgi?id=1515356
|
|
|
|
check_and_add_gcc_warning("-Wno-error=deprecated-copy")
|
|
|
|
|
2016-12-15 19:57:59 +03:00
|
|
|
# catches format/argument mismatches with printf
|
2017-11-16 21:36:33 +03:00
|
|
|
c_format_warning, cxx_format_warning = check_and_add_gcc_warning(
|
|
|
|
"-Wformat", when=depends(target)(lambda t: t.kernel != "WINNT")
|
2020-10-26 21:34:53 +03:00
|
|
|
)
|
2016-12-15 19:57:59 +03:00
|
|
|
|
2017-11-16 21:36:33 +03:00
|
|
|
# Add compile-time warnings for unprotected functions and format functions
|
|
|
|
# that represent possible security problems. Enable this only when -Wformat
|
|
|
|
# is enabled, otherwise it is an error
|
|
|
|
check_and_add_gcc_warning(
|
|
|
|
"-Wformat-security", when=c_format_warning & cxx_format_warning
|
|
|
|
)
|
|
|
|
check_and_add_gcc_warning(
|
|
|
|
"-Wformat-overflow=2", when=c_format_warning & cxx_format_warning
|
|
|
|
)
|
|
|
|
|
|
|
|
# Other MinGW specific things
|
|
|
|
with only_when(depends(target)(lambda t: t.kernel == "WINNT")):
|
|
|
|
# When compiling for Windows with gcc, we encounter lots of "#pragma warning"'s
|
|
|
|
# which is an MSVC-only pragma that GCC does not recognize.
|
|
|
|
check_and_add_gcc_warning("-Wno-unknown-pragmas")
|
|
|
|
|
|
|
|
# When compiling for Windows with gcc, gcc throws false positives and true
|
|
|
|
# positives where the callsite is ifdef-ed out
|
|
|
|
check_and_add_gcc_warning("-Wno-unused-function")
|
|
|
|
|
|
|
|
# When compiling for Windows with gcc, gcc cannot produce this warning
|
|
|
|
# correctly: it mistakes DWORD_PTR and ULONG_PTR as types you cannot
|
|
|
|
# give NULL to. (You can in fact do that.)
|
|
|
|
check_and_add_gcc_warning("-Wno-conversion-null")
|
|
|
|
|
|
|
|
# Throughout the codebase we regularly have switch statements off of enums
|
|
|
|
# without covering every value in the enum. We don't care about these warnings.
|
|
|
|
check_and_add_gcc_warning("-Wno-switch")
|
|
|
|
|
|
|
|
# Another code pattern we have is using start and end constants in enums of
|
|
|
|
# different types. We do this for safety, but then when comparing it throws
|
|
|
|
# an error, which we would like to ignore. This seems to only affect the MinGW
|
|
|
|
# build, but we're not sure why.
|
|
|
|
check_and_add_gcc_warning("-Wno-enum-compare")
|
2017-08-24 00:08:30 +03:00
|
|
|
|
2017-03-03 22:54:05 +03:00
|
|
|
# We hit this all over the place with the gtest INSTANTIATE_TEST_CASE_P macro
|
|
|
|
check_and_add_gcc_warning("-Wno-gnu-zero-variadic-macro-arguments")
|
|
|
|
|
2020-11-04 03:54:57 +03:00
|
|
|
# Make it an error to be missing function declarations for C code.
|
|
|
|
check_and_add_gcc_warning("-Werror=implicit-function-declaration", c_compiler)
|
2020-07-12 16:41:43 +03:00
|
|
|
|
2020-08-06 19:01:01 +03:00
|
|
|
# New in clang 11. We can't really do anything about this warning.
|
|
|
|
check_and_add_gcc_warning("-Wno-psabi")
|
|
|
|
|
2020-10-22 04:31:19 +03:00
|
|
|
# Disable broken missing-braces warning on old clang versions
|
|
|
|
check_and_add_gcc_warning(
|
|
|
|
"-Wno-missing-braces",
|
|
|
|
when=depends(c_compiler)(lambda c: c.type == "clang" and c.version < "6.0"),
|
|
|
|
)
|
|
|
|
|
2017-08-11 11:46:02 +03:00
|
|
|
|
2016-08-05 11:13:48 +03:00
|
|
|
# Please keep these last in this file
|
2017-12-21 05:11:22 +03:00
|
|
|
add_old_configure_assignment("_WARNINGS_CFLAGS", warnings_flags.cflags)
|
|
|
|
add_old_configure_assignment("_WARNINGS_CXXFLAGS", warnings_flags.cxxflags)
|
|
|
|
add_old_configure_assignment("_WARNINGS_HOST_CFLAGS", warnings_flags.host_cflags)
|
|
|
|
add_old_configure_assignment("_WARNINGS_HOST_CXXFLAGS", warnings_flags.host_cxxflags)
|