• 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
14ABSL_GCC_FLAGS = [
15    "-Wall",
16    "-Wextra",
17    "-Wcast-qual",
18    "-Wconversion-null",
19    "-Wformat-security",
20    "-Wmissing-declarations",
21    "-Woverlength-strings",
22    "-Wpointer-arith",
23    "-Wundef",
24    "-Wunused-local-typedefs",
25    "-Wunused-result",
26    "-Wvarargs",
27    "-Wvla",  # variable-length array
28    "-Wwrite-strings",
29    # Don't define min and max macros (Build on Windows using gcc)
30    "-DNOMINMAX",
31]
32
33ABSL_GCC_TEST_ADDITIONAL_FLAGS = [
34    "-Wno-deprecated-declarations",
35    "-Wno-missing-declarations",
36    "-Wno-self-move",
37    "-Wno-sign-compare",
38    "-Wno-unused-function",
39    "-Wno-unused-parameter",
40    "-Wno-unused-private-field",
41]
42
43ABSL_LLVM_FLAGS = [
44    "-Wall",
45    "-Wextra",
46    "-Wcast-qual",
47    "-Wconversion",
48    "-Wfloat-overflow-conversion",
49    "-Wfloat-zero-conversion",
50    "-Wfor-loop-analysis",
51    "-Wformat-security",
52    "-Wgnu-redeclared-enum",
53    "-Winfinite-recursion",
54    "-Winvalid-constexpr",
55    "-Wliteral-conversion",
56    "-Wmissing-declarations",
57    "-Woverlength-strings",
58    "-Wpointer-arith",
59    "-Wself-assign",
60    "-Wshadow-all",
61    "-Wshorten-64-to-32",
62    "-Wsign-conversion",
63    "-Wstring-conversion",
64    "-Wtautological-overlap-compare",
65    "-Wtautological-unsigned-zero-compare",
66    "-Wundef",
67    "-Wuninitialized",
68    "-Wunreachable-code",
69    "-Wunused-comparison",
70    "-Wunused-local-typedefs",
71    "-Wunused-result",
72    "-Wvla",
73    "-Wwrite-strings",
74    # Warnings that are enabled by group warning flags like -Wall that we
75    # explicitly disable.
76    "-Wno-float-conversion",
77    "-Wno-implicit-float-conversion",
78    "-Wno-implicit-int-float-conversion",
79    # Disable warnings on unknown warning flags (when warning flags are
80    # unknown on older compiler versions)
81    "-Wno-unknown-warning-option",
82    # Don't define min and max macros (Build on Windows using clang)
83    "-DNOMINMAX",
84]
85
86ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [
87    "-Wno-deprecated-declarations",
88    "-Wno-implicit-int-conversion",
89    "-Wno-missing-prototypes",
90    "-Wno-missing-variable-declarations",
91    "-Wno-shadow",
92    "-Wno-shorten-64-to-32",
93    "-Wno-sign-compare",
94    "-Wno-sign-conversion",
95    "-Wno-unreachable-code-loop-increment",
96    "-Wno-unused-function",
97    "-Wno-unused-member-function",
98    "-Wno-unused-parameter",
99    "-Wno-unused-private-field",
100    "-Wno-unused-template",
101    "-Wno-used-but-marked-unused",
102    # gtest depends on this GNU extension being offered.
103    "-Wno-gnu-zero-variadic-macro-arguments",
104]
105
106# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ...
107MSVC_BIG_WARNING_FLAGS = [
108    "/W3",
109]
110
111MSVC_WARNING_FLAGS = [
112    # Increase the number of sections available in object files
113    "/bigobj",
114    "/wd4005",  # macro-redefinition
115    "/wd4068",  # unknown pragma
116    # qualifier applied to function type has no meaning; ignored
117    "/wd4180",
118    # conversion from 'type1' to 'type2', possible loss of data
119    "/wd4244",
120    # conversion from 'size_t' to 'type', possible loss of data
121    "/wd4267",
122    # The decorated name was longer than the compiler limit
123    "/wd4503",
124    # forcing value to bool 'true' or 'false' (performance warning)
125    "/wd4800",
126]
127
128MSVC_DEFINES = [
129    "/DNOMINMAX",  # Don't define min and max macros (windows.h)
130    # Don't bloat namespace with incompatible winsock versions.
131    "/DWIN32_LEAN_AND_MEAN",
132    # Don't warn about usage of insecure C functions.
133    "/D_CRT_SECURE_NO_WARNINGS",
134    "/D_SCL_SECURE_NO_WARNINGS",
135    # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage
136    "/D_ENABLE_EXTENDED_ALIGNED_STORAGE",
137]
138
139
140def GccStyleFilterAndCombine(default_flags, test_flags):
141  """Merges default_flags and test_flags for GCC and LLVM.
142
143  Args:
144    default_flags: A list of default compiler flags
145    test_flags: A list of flags that are only used in tests
146
147  Returns:
148    A combined list of default_flags and test_flags, but with all flags of the
149    form '-Wwarning' removed if test_flags contains a flag of the form
150    '-Wno-warning'
151  """
152  remove = set(["-W" + f[5:] for f in test_flags if f[:5] == "-Wno-"])
153  return [f for f in default_flags if f not in remove] + test_flags
154
155COPT_VARS = {
156    "ABSL_GCC_FLAGS": ABSL_GCC_FLAGS,
157    "ABSL_GCC_TEST_FLAGS": GccStyleFilterAndCombine(
158        ABSL_GCC_FLAGS, ABSL_GCC_TEST_ADDITIONAL_FLAGS),
159    "ABSL_LLVM_FLAGS": ABSL_LLVM_FLAGS,
160    "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine(
161        ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS),
162    "ABSL_CLANG_CL_FLAGS":
163        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES,
164    "ABSL_CLANG_CL_TEST_FLAGS":
165        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS,
166    "ABSL_MSVC_FLAGS":
167        MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES,
168    "ABSL_MSVC_TEST_FLAGS":
169        MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES + [
170            "/wd4018",  # signed/unsigned mismatch
171            "/wd4101",  # unreferenced local variable
172            "/wd4503",  # decorated name length exceeded, name was truncated
173            "/wd4996",  # use of deprecated symbol
174            "/DNOMINMAX",  # disable the min() and max() macros from <windows.h>
175        ],
176    "ABSL_MSVC_LINKOPTS": [
177        # Object file doesn't export any previously undefined symbols
178        "-ignore:4221",
179    ],
180    # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption
181    # Standard). These flags are used for detecting whether or not the target
182    # architecture has hardware support for AES instructions which can be used
183    # to improve performance of some random bit generators.
184    "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"],
185    "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"],
186    "ABSL_RANDOM_HWAES_X64_FLAGS": [
187        "-maes",
188        "-msse4.1",
189    ],
190    "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [],
191}
192