• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Abseil compiler options.
2
3This is the source of truth for Abseil compiler options.  To modify Abseil
4compilation options:
5
6  (1) Edit the appropriate list in this file based on the platform the flag is
7      needed on.
8  (2) Run `<path_to_absl>/copts/generate_copts.py`.
9
10The generated copts are consumed by configure_copts.bzl and
11AbseilConfigureCopts.cmake.
12"""
13
14# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ...
15MSVC_BIG_WARNING_FLAGS = [
16    "/W3",
17]
18
19LLVM_BIG_WARNING_FLAGS = [
20    "-Wall",
21    "-Wextra",
22    "-Weverything",
23]
24
25# Docs on single flags is preceded by a comment.
26# Docs on groups of flags is preceded by ###.
27LLVM_DISABLE_WARNINGS_FLAGS = [
28    # Abseil does not support C++98
29    "-Wno-c++98-compat-pedantic",
30    # Turns off all implicit conversion warnings. Most are re-enabled below.
31    "-Wno-conversion",
32    "-Wno-covered-switch-default",
33    "-Wno-deprecated",
34    "-Wno-disabled-macro-expansion",
35    "-Wno-double-promotion",
36    ###
37    # Turned off as they include valid C++ code.
38    "-Wno-comma",
39    "-Wno-extra-semi",
40    "-Wno-extra-semi-stmt",
41    "-Wno-packed",
42    "-Wno-padded",
43    ###
44    # Google style does not use unsigned integers, though STL containers
45    # have unsigned types.
46    "-Wno-sign-compare",
47    ###
48    "-Wno-float-conversion",
49    "-Wno-float-equal",
50    "-Wno-format-nonliteral",
51    # Too aggressive: warns on Clang extensions enclosed in Clang-only
52    # compilation paths.
53    "-Wno-gcc-compat",
54    ###
55    # Some internal globals are necessary. Don't do this at home.
56    "-Wno-global-constructors",
57    "-Wno-exit-time-destructors",
58    ###
59    "-Wno-non-modular-include-in-module",
60    "-Wno-old-style-cast",
61    # Warns on preferred usage of non-POD types such as string_view
62    "-Wno-range-loop-analysis",
63    "-Wno-reserved-id-macro",
64    "-Wno-shorten-64-to-32",
65    "-Wno-switch-enum",
66    "-Wno-thread-safety-negative",
67    "-Wno-unknown-warning-option",
68    "-Wno-unreachable-code",
69    # Causes warnings on include guards
70    "-Wno-unused-macros",
71    "-Wno-weak-vtables",
72    # Causes warnings on usage of types/compare.h comparison operators.
73    "-Wno-zero-as-null-pointer-constant",
74    ###
75    # Implicit conversion warnings turned off by -Wno-conversion
76    # which are re-enabled below.
77    "-Wbitfield-enum-conversion",
78    "-Wbool-conversion",
79    "-Wconstant-conversion",
80    "-Wenum-conversion",
81    "-Wint-conversion",
82    "-Wliteral-conversion",
83    "-Wnon-literal-null-conversion",
84    "-Wnull-conversion",
85    "-Wobjc-literal-conversion",
86    "-Wno-sign-conversion",
87    "-Wstring-conversion",
88]
89
90LLVM_TEST_DISABLE_WARNINGS_FLAGS = [
91    "-Wno-c99-extensions",
92    "-Wno-deprecated-declarations",
93    "-Wno-missing-noreturn",
94    "-Wno-missing-prototypes",
95    "-Wno-missing-variable-declarations",
96    "-Wno-null-conversion",
97    "-Wno-shadow",
98    "-Wno-shift-sign-overflow",
99    "-Wno-sign-compare",
100    "-Wno-unused-function",
101    "-Wno-unused-member-function",
102    "-Wno-unused-parameter",
103    "-Wno-unused-private-field",
104    "-Wno-unused-template",
105    "-Wno-used-but-marked-unused",
106    "-Wno-zero-as-null-pointer-constant",
107    # gtest depends on this GNU extension being offered.
108    "-Wno-gnu-zero-variadic-macro-arguments",
109]
110
111MSVC_DEFINES = [
112    "/DNOMINMAX",  # Don't define min and max macros (windows.h)
113    # Don't bloat namespace with incompatible winsock versions.
114    "/DWIN32_LEAN_AND_MEAN",
115    # Don't warn about usage of insecure C functions.
116    "/D_CRT_SECURE_NO_WARNINGS",
117    "/D_SCL_SECURE_NO_WARNINGS",
118    # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage
119    "/D_ENABLE_EXTENDED_ALIGNED_STORAGE",
120]
121
122COPT_VARS = {
123    "ABSL_GCC_FLAGS": [
124        "-Wall",
125        "-Wextra",
126        "-Wcast-qual",
127        "-Wconversion-null",
128        "-Wmissing-declarations",
129        "-Woverlength-strings",
130        "-Wpointer-arith",
131        "-Wunused-local-typedefs",
132        "-Wunused-result",
133        "-Wvarargs",
134        "-Wvla",  # variable-length array
135        "-Wwrite-strings",
136        # gcc-4.x has spurious missing field initializer warnings.
137        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750
138        # Remove when gcc-4.x is no longer supported.
139        "-Wno-missing-field-initializers",
140        # Google style does not use unsigned integers, though STL containers
141        # have unsigned types.
142        "-Wno-sign-compare",
143    ],
144    "ABSL_GCC_TEST_FLAGS": [
145        "-Wno-conversion-null",
146        "-Wno-deprecated-declarations",
147        "-Wno-missing-declarations",
148        "-Wno-sign-compare",
149        "-Wno-unused-function",
150        "-Wno-unused-parameter",
151        "-Wno-unused-private-field",
152    ],
153    "ABSL_LLVM_FLAGS":
154        LLVM_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS,
155    "ABSL_LLVM_TEST_FLAGS":
156        LLVM_TEST_DISABLE_WARNINGS_FLAGS,
157    "ABSL_CLANG_CL_FLAGS":
158        (MSVC_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS + MSVC_DEFINES),
159    "ABSL_CLANG_CL_TEST_FLAGS":
160        LLVM_TEST_DISABLE_WARNINGS_FLAGS,
161    "ABSL_MSVC_FLAGS":
162        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [
163            # Increase the number of sections available in object files
164            "/bigobj",
165            "/wd4005",  # macro-redefinition
166            "/wd4068",  # unknown pragma
167            # qualifier applied to function type has no meaning; ignored
168            "/wd4180",
169            # conversion from 'type1' to 'type2', possible loss of data
170            "/wd4244",
171            # conversion from 'size_t' to 'type', possible loss of data
172            "/wd4267",
173            # The decorated name was longer than the compiler limit
174            "/wd4503",
175            # forcing value to bool 'true' or 'false' (performance warning)
176            "/wd4800",
177        ],
178    "ABSL_MSVC_TEST_FLAGS": [
179        "/wd4018",  # signed/unsigned mismatch
180        "/wd4101",  # unreferenced local variable
181        "/wd4503",  # decorated name length exceeded, name was truncated
182        "/wd4996",  # use of deprecated symbol
183        "/DNOMINMAX",  # disable the min() and max() macros from <windows.h>
184    ],
185    "ABSL_MSVC_LINKOPTS": [
186        # Object file doesn't export any previously undefined symbols
187        "-ignore:4221",
188    ],
189    # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption
190    # Standard). These flags are used for detecting whether or not the target
191    # architecture has hardware support for AES instructions which can be used
192    # to improve performance of some random bit generators.
193    "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"],
194    "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"],
195    "ABSL_RANDOM_HWAES_X64_FLAGS": [
196        "-maes",
197        "-msse4.1",
198    ],
199    "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [],
200}
201