Bug 1407343 Silence multiple classes of warnings for the MinGW build, including not enabling format warnings unless -Wformat is set
MozReview-Commit-ID: ALmo1hbqVxC
old mode 100644
new mode 100755
--- a/build/moz.configure/compile-checks.configure
+++ b/build/moz.configure/compile-checks.configure
@@ -100,16 +100,18 @@ def check_and_add_flags(flag, cflags, cx
if compiler is not None:
compilers = (compiler,)
else:
compilers = (c_compiler, cxx_compiler)
if when is None:
when = always
+ results = []
+
if test_flags:
flags = test_flags
else:
flags = [flag]
for c in compilers:
assert c in (c_compiler, cxx_compiler)
lang, list_of_flags = {
@@ -127,16 +129,20 @@ def check_and_add_flags(flag, cflags, cx
flags=flags, when=result,
check_msg='whether the %s compiler supports %s' % (lang, flag))
@depends(result, list_of_flags)
def maybe_add_flag(result, list_of_flags):
if result:
list_of_flags.append(flag)
+ results.append(result)
+
+ return tuple(results)
+
@dependable
def warnings_cflags():
return []
@dependable
def warnings_cxxflags():
@@ -163,18 +169,18 @@ def check_and_add_gcc_warning(warning, c
# add the negated form to the flags variable.
if warning.startswith('-Wno-') and not warning.startswith('-Wno-error='):
flags = ['-Werror', '-W' + warning[5:]]
elif warning.startswith('-Werror='):
flags = [warning]
else:
flags = ['-Werror', warning]
- check_and_add_flags(warning, warnings_cflags, warnings_cxxflags,
- flags, compiler=compiler, when=when, check=check)
+ return check_and_add_flags(warning, warnings_cflags, warnings_cxxflags,
+ flags, compiler=compiler, when=when, check=check)
# Add the given warning to the list of warning flags for the build.
# - `warning` is the warning flag (e.g. -Wfoo)
# - `compiler` (optional) is the compiler to add the flag for (c_compiler or
# cxx_compiler, from toolchain.configure). When omitted, the warning flag
# is added for both compilers.
# - `when` (optional) is a @depends function or option name conditioning
@@ -207,18 +213,18 @@ def compilation_cxxflags():
# when the warning flag is wanted.
# - `check`, when not set, skips checking whether the flag is supported and
# adds it to the list of flags unconditionally. This is only meant for
# add_gcc_flag().
@template
def check_and_add_gcc_flag(flag, compiler=None, when=None, check=True):
flags = ['-Werror', flag]
- check_and_add_flags(flag, compilation_cflags, compilation_cxxflags,
- flags, compiler=compiler, when=when, check=check)
+ return check_and_add_flags(flag, compilation_cflags, compilation_cxxflags,
+ flags, compiler=compiler, when=when, check=check)
# Add the given flag to the list of flags for the build.
# - `flag` is the flag (e.g. -fno-sized-deallocation)
# - `compiler` (optional) is the compiler to add the flag for (c_compiler or
# cxx_compiler, from toolchain.configure). When omitted, the flag is added
# for both compilers.
# - `when` (optional) is a @depends function or option name conditioning
--- a/build/moz.configure/warnings.configure
+++ b/build/moz.configure/warnings.configure
@@ -100,41 +100,55 @@ check_and_add_gcc_warning('-Wno-error=ar
# can't get rid of those PGO warnings
check_and_add_gcc_warning('-Wno-error=coverage-mismatch', when='MOZ_PGO')
# false positives depending on optimizations
check_and_add_gcc_warning('-Wno-error=free-nonheap-object')
# catches format/argument mismatches with printf
-check_and_add_gcc_warning('-Wformat')
+c_format_warning, cxx_format_warning = check_and_add_gcc_warning(
+ '-Wformat', when=depends(target)(lambda t: t.kernel != 'WINNT'))
-# We use mix of both POSIX and Win32 printf format across the tree, so format
-# warnings are useless on mingw.
-check_and_add_gcc_warning('-Wno-format',
- when=depends(target)(lambda t: t.kernel == 'WINNT'))
+# 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, 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=depends(target)(lambda t: t.kernel == 'WINNT'))
+ # 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')
-# 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=depends(target)(lambda t: t.kernel == 'WINNT'))
+ # 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')
# 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')
-# Add compile-time warnings for unprotected functions and format functions
-# that represent possible security problems
-check_and_add_gcc_warning('-Wformat-security')
-check_and_add_gcc_warning('-Wformat-overflow=2')
-
# Disable a warning with gcc 7. See bug 1320656
# We are far from using C++17 and the impact of the warning will be
# limited to a potential public ABI.
# Currently only affecting js/
check_and_add_gcc_warning('-Wno-noexcept-type', cxx_compiler,
when=depends(build_project)
(lambda build_project: build_project == 'js'))
--- a/dom/security/moz.build
+++ b/dom/security/moz.build
@@ -44,12 +44,8 @@ include('/ipc/chromium/chromium-config.m
FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'/caps',
'/docshell/base', # for nsDocShell.h
'/netwerk/base',
'/netwerk/protocol/data', # for nsDataHandler.h
]
-
-if CONFIG['GNU_CC']:
- CFLAGS += ['-Wformat-security']
- CXXFLAGS += ['-Wformat-security']