DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
# -*- 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/.

js_option('--enable-warnings-as-errors', env='MOZ_ENABLE_WARNINGS_AS_ERRORS',
          default=depends('MOZ_AUTOMATION', '--help')(lambda x, _: bool(x)),
          help='Enable treating warnings as errors')

add_old_configure_assignment(
    'MOZ_ENABLE_WARNINGS_AS_ERRORS',
    depends('--enable-warnings-as-errors')(lambda x: bool(x)))


# GCC/Clang warnings:
# https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Warning-Options.html

# lots of useful warnings
add_gcc_warning('-Wall')

# 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')

# function declaration hides virtual function from base class
add_gcc_warning('-Woverloaded-virtual', cxx_compiler)

# catches pointer arithmetic using NULL or sizeof(void)
add_gcc_warning('-Wpointer-arith')

# 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')
check_and_add_gcc_warning('-Wunreachable-code-return')

# 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')

# catches issues around loops
check_and_add_gcc_warning('-Wloop-analysis')

# catches C++ version forward-compat issues
check_and_add_gcc_warning('-Wc++1z-compat', cxx_compiler)

# catches possible misuse of the comma operator
check_and_add_gcc_warning('-Wcomma', cxx_compiler)

# catches duplicated conditions in if-else-if chains
check_and_add_gcc_warning('-Wduplicated-cond')

# catches unintentional switch case fallthroughs
check_and_add_gcc_warning('-Wimplicit-fallthrough', cxx_compiler)

# 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')

# 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
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
c_format_warning, cxx_format_warning = check_and_add_gcc_warning(
    '-Wformat', 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, 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')

# 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')

# 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'))


# Please keep these last in this file
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)