Turn on -Wall and copy diagnostic set from Google toolchain (#2541)
We already pass with all of these, but haven't had them enabled in OSS
builds. Rather than piecemeal enabling warnings, let's just turn ~all
of them on. This is pretty much the set used at Google (+/-, it's spread
across quite a few files so difficult to track everything down), so
this also reduces maintainer pain encountering these errors on import.
This will avoid having to do this one at a time like in
https://github.com/google/iree/pull/2296 and
https://github.com/google/iree/pull/2294 and
https://github.com/google/iree/pull/2513
diff --git a/.bazelrc b/.bazelrc
index 483e8df..4aab07e 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -40,26 +40,6 @@
# either clang or gcc and are curated based on need.
###############################################################################
-# Treat warnings in-workspace as errors.
-build:generic_clang --per_file_copt=-external/.*-Werror
-# ...and silence them outside of the workspace.
-build:generic_clang --per_file_copt=external/.*@-w
-
-# Disable warnings we don't care about.
-build:generic_clang --copt=-Wno-unused-local-typedef
-build:generic_clang --copt=-Wno-unused-private-field
-build:generic_clang --copt=-Wno-unused-const-variable
-# Matches upstream. Cannot impact due to extern C inclusion method.
-build:generic_clang --copt=-Wno-extern-c-compat
-# Technically UB but needed for intrusive ptrs
-build:generic_clang --copt=-Wno-invalid-offsetof
-build:generic_clang --copt=-Wno-unused-function
-
-# Enable warnings we do care about.
-build:generic_clang --copt=-Wimplicit-fallthrough
-build:generic_clang --copt=-Wthread-safety-analysis
-build:generic_clang --copt=-Wunused-variable
-
# C++14 standard version is required.
build:generic_clang --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
@@ -67,6 +47,73 @@
# This is a good compromise between runtime and debugability.
build:generic_clang --copt=-UNDEBUG
+# Treat warnings in-workspace as errors.
+build:generic_clang --per_file_copt=-external/.*-Werror
+# ...and silence them outside of the workspace.
+build:generic_clang --per_file_copt=external/.*@-w
+
+# LINT.IfChange(clang_diagnostics)
+# Set clang diagnostics. These largely match the set of warnings used within
+# Google. They have not been audited super carefully by the IREE team but are
+# generally thought to be a good set and consistency with those used internally
+# is very useful when importing. If you feel hat some of these should be
+# different, please raise an issue!
+
+build:generic_clang --copt=-Wall
+
+# Disable warnings we don't care about or that generally have a low signal/noise
+# ratio.
+build:generic_clang --copt=-Wno-ambiguous-member-template
+build:generic_clang --copt=-Wno-char-subscripts
+build:generic_clang --copt=-Wno-error=deprecated-declarations
+build:generic_clang --copt=-Wno-extern-c-compat # Matches upstream. Cannot impact due to extern C inclusion method.
+build:generic_clang --copt=-Wno-gnu-alignof-expression
+build:generic_clang --copt=-Wno-gnu-variable-sized-type-not-at-end
+build:generic_clang --copt=-Wno-ignored-optimization-argument
+build:generic_clang --copt=-Wno-invalid-offsetof # Technically UB but needed for intrusive ptrs
+build:generic_clang --copt=-Wno-invalid-source-encoding
+build:generic_clang --copt=-Wno-mismatched-tags
+build:generic_clang --copt=-Wno-pointer-sign
+build:generic_clang --copt=-Wno-reserved-user-defined-literal
+build:generic_clang --copt=-Wno-return-type-c-linkage
+build:generic_clang --copt=-Wno-self-assign-overloaded
+build:generic_clang --copt=-Wno-sign-compare
+build:generic_clang --copt=-Wno-signed-unsigned-wchar
+build:generic_clang --copt=-Wno-strict-overflow
+build:generic_clang --copt=-Wno-trigraphs
+build:generic_clang --copt=-Wno-unknown-pragmas
+build:generic_clang --copt=-Wno-unknown-warning-option
+build:generic_clang --copt=-Wno-unused-command-line-argument
+build:generic_clang --copt=-Wno-unused-const-variable
+build:generic_clang --copt=-Wno-unused-function
+build:generic_clang --copt=-Wno-unused-local-typedef
+build:generic_clang --copt=-Wno-unused-private-field
+build:generic_clang --copt=-Wno-user-defined-warnings
+
+# Explicitly enable some additional warnings.
+# Some of these aren't on by default, or under -Wall, or are subsets of warnings
+# turned off above.
+build:generic_clang --copt=-Wctad-maybe-unsupported
+build:generic_clang --copt=-Wfloat-overflow-conversion
+build:generic_clang --copt=-Wfloat-zero-conversion
+build:generic_clang --copt=-Wfor-loop-analysis
+build:generic_clang --copt=-Wformat-security
+build:generic_clang --copt=-Wgnu-redeclared-enum
+build:generic_clang --copt=-Wimplicit-fallthrough
+build:generic_clang --copt=-Winfinite-recursion
+build:generic_clang --copt=-Wliteral-conversion
+build:generic_clang --copt=-Wnon-virtual-dtor
+build:generic_clang --copt=-Woverloaded-virtual
+build:generic_clang --copt=-Wself-assign
+build:generic_clang --copt=-Wstring-conversion
+build:generic_clang --copt=-Wtautological-overlap-compare
+build:generic_clang --copt=-Wthread-safety
+build:generic_clang --copt=-Wthread-safety-beta
+build:generic_clang --copt=-Wunused-comparison
+build:generic_clang --copt=-Wunused-variable
+build:generic_clang --copt=-Wvla
+# LINT.ThenChange(https://github.com/google/iree/blob/main/build_tools/cmake/iree_copts.cmake:clang_diagnostics)
+
###############################################################################
# Options for building with address sanitizer.
# https://github.com/google/sanitizers/wiki/AddressSanitizer
diff --git a/build_tools/cmake/iree_copts.cmake b/build_tools/cmake/iree_copts.cmake
index 88eb477..28d5fe3 100644
--- a/build_tools/cmake/iree_copts.cmake
+++ b/build_tools/cmake/iree_copts.cmake
@@ -44,20 +44,75 @@
iree_select_compiler_opts(IREE_DEFAULT_COPTS
CLANG
+ # LINT.IfChange(clang_diagnostics)
+ # Set clang diagnostics. These largely match the set of warnings used within
+ # Google. They have not been audited super carefully by the IREE team but
+ # are generally thought to be a good set and consistency with those used
+ # internally is very useful when importing. If you feel hat some of these
+ # should be different, please raise an issue!
+ "-Wall"
+
+ # Disable warnings we don't care about or that generally have a low
+ # signal/noise ratio.
+ "-Wno-ambiguous-member-template"
+ "-Wno-char-subscripts"
+ "-Wno-error=deprecated-declarations"
+ "-Wno-extern-c-compat" # Matches upstream. Cannot impact due to extern C inclusion method.
+ "-Wno-gnu-alignof-expression"
+ "-Wno-gnu-variable-sized-type-not-at-end"
+ "-Wno-ignored-optimization-argument"
+ "-Wno-invalid-offsetof" # Technically UB but needed for intrusive ptrs
+ "-Wno-invalid-source-encoding"
+ "-Wno-mismatched-tags"
+ "-Wno-pointer-sign"
+ "-Wno-reserved-user-defined-literal"
+ "-Wno-return-type-c-linkage"
+ "-Wno-self-assign-overloaded"
+ "-Wno-sign-compare"
+ "-Wno-signed-unsigned-wchar"
+ "-Wno-strict-overflow"
+ "-Wno-trigraphs"
+ "-Wno-unknown-pragmas"
+ "-Wno-unknown-warning-option"
+ "-Wno-unused-command-line-argument"
+ "-Wno-unused-const-variable"
+ "-Wno-unused-function"
+ "-Wno-unused-local-typedef"
+ "-Wno-unused-private-field"
+ "-Wno-user-defined-warnings"
+ # Explicitly enable some additional warnings.
+ # Some of these aren't on by default, or under -Wall, or are subsets of
+ # warnings turned off above.
+ "-Wno-ambiguous-member-template"
+ "-Wctad-maybe-unsupported"
+ "-Wfloat-overflow-conversion"
+ "-Wfloat-zero-conversion"
+ "-Wfor-loop-analysis"
+ "-Wformat-security"
+ "-Wgnu-redeclared-enum"
+ "-Wimplicit-fallthrough"
+ "-Winfinite-recursion"
+ "-Wliteral-conversion"
+ "-Wnon-virtual-dtor"
+ "-Woverloaded-virtual"
+ "-Wself-assign"
+ "-Wstring-conversion"
+ "-Wtautological-overlap-compare"
+ "-Wthread-safety"
+ "-Wthread-safety-beta"
+ "-Wunused-comparison"
+ "-Wunused-variable"
+ "-Wvla"
+ # LINT.ThenChange(https://github.com/google/iree/blob/main/.bazelrc:clang_diagnostics)
+
+ # Turn off some additional warnings (CMake only)
"-Wno-strict-prototypes"
"-Wno-shadow-uncaptured-local"
"-Wno-gnu-zero-variadic-macro-arguments"
"-Wno-shadow-field-in-constructor"
"-Wno-unreachable-code-return"
- "-Wno-unused-private-field"
"-Wno-missing-variable-declarations"
"-Wno-gnu-label-as-value"
- "-Wno-unused-local-typedef"
- "-Wno-gnu-zero-variadic-macro-arguments"
- # Enable some warnings
- "-Wimplicit-fallthrough"
- "-Wthread-safety-analysis"
- "-Wunused-variable"
CLANG_OR_GCC
"-Wno-unused-parameter"
"-Wno-undef"