• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 the gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16Includes default copts.
17"""
18
19# This is a list of llvm flags to be used when being built with use_strict_warning=1
20GRPC_LLVM_WARNING_FLAGS = [
21    # Enable all & extra warnings
22    "-Wall",
23    "-Wextra",
24    # Avoid some known traps
25    "-Wimplicit-fallthrough",
26    # Consider warnings as errors
27    "-Werror",
28    # Ignore unknown warning flags
29    "-Wno-unknown-warning-option",
30    # A list of enabled flags coming from internal build system
31    "-Wc++20-extensions",
32    "-Wctad-maybe-unsupported",
33    "-Wdeprecated-increment-bool",
34    "-Wfloat-overflow-conversion",
35    "-Wfloat-zero-conversion",
36    "-Wfor-loop-analysis",
37    "-Wformat-security",
38    "-Wgnu-redeclared-enum",
39    "-Winfinite-recursion",
40    "-Wliteral-conversion",
41    "-Wnon-virtual-dtor",
42    "-Woverloaded-virtual",
43    "-Wself-assign",
44    "-Wstring-conversion",
45    "-Wtautological-overlap-compare",
46    "-Wthread-safety-analysis",
47    "-Wthread-safety-beta",
48    "-Wunused-but-set-variable",
49    "-Wunused-comparison",
50    "-Wvla",
51    # -Wextra compatibility between gcc and clang
52    "-Wtype-limits",
53    # A list of disabled flags coming from internal build system
54    "-Wno-string-concatenation",
55    # Exceptions but will be removed
56    "-Wno-deprecated-declarations",
57    "-Wno-unused-function",
58    # alignment issues
59    "-Walign-mismatch",
60    "-Wover-aligned",
61    "-Wunaligned-access",
62]
63
64GRPC_LLVM_WINDOWS_WARNING_FLAGS = GRPC_LLVM_WARNING_FLAGS + [
65    ### Some checks that are missing with clang-cl
66    "-Wthread-safety",
67    "-Wreorder-ctor",
68
69    ### Avoid some checks that are default on clang-cl
70    "-Wno-c++98-compat-pedantic",
71    "-Wno-missing-prototypes",
72    "-Wno-thread-safety-precise",  # too many aliases
73
74    # abseil offenses
75    "-Wno-comma",
76    "-Wno-deprecated-redundant-constexpr-static-def",
77    "-Wno-deprecated",  # remove when the above works in all clang versions we test with
78    "-Wno-float-equal",
79    "-Wno-gcc-compat",
80    "-Wno-reserved-identifier",
81    "-Wno-thread-safety-negative",
82    "-Wno-sign-compare",
83
84    # re2 offenses
85    "-Wno-zero-as-null-pointer-constant",
86
87    # ares offenses
88    "-Wno-macro-redefined",
89
90    # protobuf offenses
91    "-Wno-cast-align",
92    "-Wno-inconsistent-missing-destructor-override",
93
94    # xxhash offenses
95    "-Wno-disabled-macro-expansion",
96
97    # benchmark offenses
98    "-Wno-shift-sign-overflow",
99
100    # Evidently nodiscard is inappropriately pinned as a C++17 feature
101    "-Wno-c++17-attribute-extensions",
102
103    # declarations are not used in many places
104    "-Wno-missing-variable-declarations",
105
106    # TODO: delete iomgr
107    "-Wno-old-style-cast",
108    "-Wno-cast-qual",
109    "-Wno-unused-member-function",
110    "-Wno-unused-template",
111
112    # TODO(hork): see if the TraceFlag offense can be removed
113    "-Wno-global-constructors",
114    # TODO(hork): clean up EE offenses
115    "-Wno-missing-field-initializers",
116    "-Wno-non-virtual-dtor",
117    "-Wno-thread-safety-reference-return",
118
119    # TODO(ctiller): offense: dump_args. signed to unsigned
120    "-Wno-sign-conversion",
121    "-Wno-shorten-64-to-32",
122
123    # TODO: general cleanup required. Maybe new developer or rainy day projects.
124    "-Wno-unreachable-code-break",
125    "-Wno-unreachable-code-return",
126    "-Wno-unreachable-code",
127    "-Wno-used-but-marked-unused",
128    "-Wno-newline-eof",
129    "-Wno-unused-const-variable",
130    "-Wno-extra-semi",
131    "-Wno-extra-semi-stmt",
132    "-Wno-suggest-destructor-override",
133    "-Wno-shadow",
134    "-Wno-missing-noreturn",
135    "-Wno-nested-anon-types",
136    "-Wno-gnu-anonymous-struct",
137    "-Wno-nonportable-system-include-path",
138    "-Wno-microsoft-cast",
139    "-Wno-exit-time-destructors",
140    "-Wno-undef",  # #if <MACRO_NAME> to #ifdef <MACRO_NAME>
141    "-Wno-unused-macros",
142    "-Wno-redundant-parens",
143    "-Wno-undefined-func-template",
144    "-Wno-gnu-zero-variadic-macro-arguments",
145    "-Wno-double-promotion",
146    "-Wno-implicit-float-conversion",
147    "-Wno-implicit-int-conversion",
148    "-Wno-float-conversion",
149    "-Wno-unused-parameter",
150    "-Wno-suggest-override",
151    "-Wno-documentation",
152    "-Wno-documentation-unknown-command",
153    "-Wno-unsafe-buffer-usage",
154
155    ### possibly bad warnings for this codebase
156    "-Wno-covered-switch-default",
157    "-Wno-switch-default",
158    "-Wno-switch-enum",
159    "-Wno-c99-extensions",
160    "-Wno-unused-private-field",  # GRPC_UNUSED does not appear to work for private fields
161]
162
163GRPC_DEFAULT_COPTS = select({
164    "//:use_strict_warning": GRPC_LLVM_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"],
165    "//:use_strict_warning_windows": GRPC_LLVM_WINDOWS_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"],
166    "//conditions:default": [],
167})
168