blob: 26eb69dce4e5799d79a5e7ee65d118f55685c8b1 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
mmentovai@google.comf1ea2fa2008-08-21 22:26:064
5#ifndef BASE_COMPILER_SPECIFIC_H_
6#define BASE_COMPILER_SPECIFIC_H_
7
8#include "build/build_config.h"
9
Nico Weberfb053cc2020-03-03 13:33:0510#if defined(COMPILER_MSVC) && !defined(__clang__)
Nico Weber59791812019-07-27 04:02:1111#error "Only clang-cl is supported on Windows, see https://crbug.com/988071"
12#endif
13
Jan Wilken Dörrief8d479d2020-11-23 12:21:1314// This is a wrapper around `__has_cpp_attribute`, which can be used to test for
15// the presence of an attribute. In case the compiler does not support this
16// macro it will simply evaluate to 0.
17//
18// References:
19// https://wg21.link/sd6#testing-for-the-presence-of-an-attribute-__has_cpp_attribute
20// https://wg21.link/cpp.cond#:__has_cpp_attribute
21#if defined(__has_cpp_attribute)
22#define HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
23#else
24#define HAS_CPP_ATTRIBUTE(x) 0
25#endif
26
Peter Kasting64c67dd2022-05-12 18:11:5127// A wrapper around `__has_attribute`, similar to HAS_CPP_ATTRIBUTE.
28#if defined(__has_attribute)
29#define HAS_ATTRIBUTE(x) __has_attribute(x)
30#else
31#define HAS_ATTRIBUTE(x) 0
32#endif
33
Jann Horn9e4b48552021-03-04 14:34:2734// A wrapper around `__has_builtin`, similar to HAS_CPP_ATTRIBUTE.
35#if defined(__has_builtin)
36#define HAS_BUILTIN(x) __has_builtin(x)
37#else
38#define HAS_BUILTIN(x) 0
39#endif
40
eroman@chromium.org2149cc622012-02-14 01:12:1241// Annotate a function indicating it should not be inlined.
42// Use like:
43// NOINLINE void DoStuff() { ... }
Peter Kastingf541f7782023-03-10 23:44:4644#if defined(__clang__) && HAS_ATTRIBUTE(noinline)
45#define NOINLINE [[clang::noinline]]
46#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline)
eroman@chromium.org2149cc622012-02-14 01:12:1247#define NOINLINE __attribute__((noinline))
48#elif defined(COMPILER_MSVC)
49#define NOINLINE __declspec(noinline)
50#else
davemoore@chromium.org50795a02011-05-09 20:11:0151#define NOINLINE
evan@chromium.orgf50595102010-10-08 16:20:3252#endif
53
Peter Kastingf541f7782023-03-10 23:44:4654#if defined(__clang__) && defined(NDEBUG) && HAS_ATTRIBUTE(always_inline)
55#define ALWAYS_INLINE [[clang::always_inline]] inline
56#elif defined(COMPILER_GCC) && defined(NDEBUG) && HAS_ATTRIBUTE(always_inline)
palmer58184a8282016-11-08 19:15:3957#define ALWAYS_INLINE inline __attribute__((__always_inline__))
Ivan Krasin9c098a0d2018-08-05 03:57:5758#elif defined(COMPILER_MSVC) && defined(NDEBUG)
palmer58184a8282016-11-08 19:15:3959#define ALWAYS_INLINE __forceinline
60#else
61#define ALWAYS_INLINE inline
62#endif
63
Olivier Li19d89252020-05-13 17:57:5564// Annotate a function indicating it should never be tail called. Useful to make
65// sure callers of the annotated function are never omitted from call-stacks.
66// To provide the complementary behavior (prevent the annotated function from
67// being omitted) look at NOINLINE. Also note that this doesn't prevent code
68// folding of multiple identical caller functions into a single signature. To
Bruce Dawson7915efd2021-01-27 18:07:5869// prevent code folding, see NO_CODE_FOLDING() in base/debug/alias.h.
Olivier Li19d89252020-05-13 17:57:5570// Use like:
Daniel Chengddf1b222023-02-02 02:41:5271// NOT_TAIL_CALLED void FooBar();
Peter Kasting64c67dd2022-05-12 18:11:5172#if defined(__clang__) && HAS_ATTRIBUTE(not_tail_called)
Peter Kastingf541f7782023-03-10 23:44:4673#define NOT_TAIL_CALLED [[clang::not_tail_called]]
Olivier Li19d89252020-05-13 17:57:5574#else
75#define NOT_TAIL_CALLED
76#endif
77
jbates@chromium.orgcd924d62012-02-23 17:52:2078// Specify memory alignment for structs, classes, etc.
79// Use like:
80// class ALIGNAS(16) MyClass { ... }
81// ALIGNAS(16) int array[4];
brettw16289b3e2017-06-13 21:58:4082//
83// In most places you can use the C++11 keyword "alignas", which is preferred.
84//
Peter Kastingf541f7782023-03-10 23:44:4685// Historically, compilers had trouble mixing __attribute__((...)) syntax with
86// alignas(...) syntax. However, at least Clang is very accepting nowadays. It
87// may be that this macro can be removed entirely.
88#if defined(__clang__)
89#define ALIGNAS(byte_alignment) alignas(byte_alignment)
90#elif defined(COMPILER_MSVC)
jbates@chromium.orgcd924d62012-02-23 17:52:2091#define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
Peter Kastingf541f7782023-03-10 23:44:4692#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(aligned)
jbates@chromium.orgcd924d62012-02-23 17:52:2093#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
94#endif
95
Jan Wilken Dörrief8d479d2020-11-23 12:21:1396// In case the compiler supports it NO_UNIQUE_ADDRESS evaluates to the C++20
97// attribute [[no_unique_address]]. This allows annotating data members so that
98// they need not have an address distinct from all other non-static data members
99// of its class.
100//
101// References:
102// * https://en.cppreference.com/w/cpp/language/attributes/no_unique_address
103// * https://wg21.link/dcl.attr.nouniqueaddr
104#if HAS_CPP_ATTRIBUTE(no_unique_address)
105#define NO_UNIQUE_ADDRESS [[no_unique_address]]
106#else
107#define NO_UNIQUE_ADDRESS
108#endif
109
Peter Kastingf541f7782023-03-10 23:44:46110// Tells the compiler a function is using a printf-style format string.
evan@chromium.org34b2b002009-11-20 06:53:28111// |format_param| is the one-based index of the format string parameter;
112// |dots_param| is the one-based index of the "..." parameter.
113// For v*printf functions (which take a va_list), pass 0 for dots_param.
114// (This is undocumented but matches what the system C headers do.)
Nico Weberfc7c8dd2019-02-28 21:28:44115// For member functions, the implicit this parameter counts as index 1.
Peter Kastingf541f7782023-03-10 23:44:46116#if (defined(COMPILER_GCC) || defined(__clang__)) && HAS_ATTRIBUTE(format)
evan@chromium.org34b2b002009-11-20 06:53:28117#define PRINTF_FORMAT(format_param, dots_param) \
Vitaly Buka2b790762019-12-20 21:11:48118 __attribute__((format(printf, format_param, dots_param)))
evan@chromium.orgf50595102010-10-08 16:20:32119#else
120#define PRINTF_FORMAT(format_param, dots_param)
121#endif
evan@chromium.org34b2b002009-11-20 06:53:28122
123// WPRINTF_FORMAT is the same, but for wide format strings.
evan@chromium.orgf50595102010-10-08 16:20:32124// This doesn't appear to yet be implemented in any compiler.
evan@chromium.org34b2b002009-11-20 06:53:28125// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 .
126#define WPRINTF_FORMAT(format_param, dots_param)
127// If available, it would look like:
128// __attribute__((format(wprintf, format_param, dots_param)))
129
etienneb4e9250a2016-11-18 18:47:53130// Sanitizers annotations.
Peter Kasting64c67dd2022-05-12 18:11:51131#if HAS_ATTRIBUTE(no_sanitize)
etienneb4e9250a2016-11-18 18:47:53132#define NO_SANITIZE(what) __attribute__((no_sanitize(what)))
133#endif
etienneb4e9250a2016-11-18 18:47:53134#if !defined(NO_SANITIZE)
135#define NO_SANITIZE(what)
136#endif
137
eugenis@chromium.org75086be2013-03-20 21:18:22138// MemorySanitizer annotations.
Xiaohan Wang38e4ebb2022-01-19 06:57:43139#if defined(MEMORY_SANITIZER) && !BUILDFLAG(IS_NACL)
earthdok@chromium.orgeb82dfb2014-02-03 19:51:17140#include <sanitizer/msan_interface.h>
eugenis@chromium.org75086be2013-03-20 21:18:22141
142// Mark a memory region fully initialized.
143// Use this to annotate code that deliberately reads uninitialized data, for
144// example a GC scavenging root set pointers from the stack.
Vitaly Buka2b790762019-12-20 21:11:48145#define MSAN_UNPOISON(p, size) __msan_unpoison(p, size)
thestig1a42b4072015-03-16 22:36:55146
147// Check a memory region for initializedness, as if it was being used here.
148// If any bits are uninitialized, crash with an MSan report.
149// Use this to sanitize data which MSan won't be able to track, e.g. before
150// passing data to another process via shared memory.
151#define MSAN_CHECK_MEM_IS_INITIALIZED(p, size) \
Vitaly Buka2b790762019-12-20 21:11:48152 __msan_check_mem_is_initialized(p, size)
eugenis@chromium.org75086be2013-03-20 21:18:22153#else // MEMORY_SANITIZER
thestig1a42b4072015-03-16 22:36:55154#define MSAN_UNPOISON(p, size)
155#define MSAN_CHECK_MEM_IS_INITIALIZED(p, size)
eugenis@chromium.org75086be2013-03-20 21:18:22156#endif // MEMORY_SANITIZER
157
krasin825ce482016-08-27 11:01:11158// DISABLE_CFI_PERF -- Disable Control Flow Integrity for perf reasons.
159#if !defined(DISABLE_CFI_PERF)
krasin40f7c782016-09-22 19:04:27160#if defined(__clang__) && defined(OFFICIAL_BUILD)
Peter Kastingf541f7782023-03-10 23:44:46161#define DISABLE_CFI_PERF NO_SANITIZE("cfi")
krasin825ce482016-08-27 11:01:11162#else
163#define DISABLE_CFI_PERF
164#endif
165#endif
166
Will Harris9a033b02020-07-11 01:26:54167// DISABLE_CFI_ICALL -- Disable Control Flow Integrity indirect call checks.
Alex Gough36579802022-07-25 20:20:46168// Security Note: if you just need to allow calling of dlsym functions use
169// DISABLE_CFI_DLSYM.
Will Harris9a033b02020-07-11 01:26:54170#if !defined(DISABLE_CFI_ICALL)
Xiaohan Wang38e4ebb2022-01-19 06:57:43171#if BUILDFLAG(IS_WIN)
Will Harris9a033b02020-07-11 01:26:54172// Windows also needs __declspec(guard(nocf)).
173#define DISABLE_CFI_ICALL NO_SANITIZE("cfi-icall") __declspec(guard(nocf))
174#else
175#define DISABLE_CFI_ICALL NO_SANITIZE("cfi-icall")
176#endif
177#endif
178#if !defined(DISABLE_CFI_ICALL)
179#define DISABLE_CFI_ICALL
180#endif
181
Alex Gough36579802022-07-25 20:20:46182// DISABLE_CFI_DLSYM -- applies DISABLE_CFI_ICALL on platforms where dlsym
183// functions must be called. Retains CFI checks on platforms where loaded
184// modules participate in CFI (e.g. Windows).
185#if !defined(DISABLE_CFI_DLSYM)
186#if BUILDFLAG(IS_WIN)
187// Windows modules register functions when loaded so can be checked by CFG.
188#define DISABLE_CFI_DLSYM
189#else
190#define DISABLE_CFI_DLSYM DISABLE_CFI_ICALL
191#endif
192#endif
193#if !defined(DISABLE_CFI_DLSYM)
194#define DISABLE_CFI_DLSYM
195#endif
196
jochen@chromium.org5a8d4ce2013-12-18 17:42:27197// Macro useful for writing cross-platform function pointers.
198#if !defined(CDECL)
Xiaohan Wang38e4ebb2022-01-19 06:57:43199#if BUILDFLAG(IS_WIN)
jochen@chromium.org5a8d4ce2013-12-18 17:42:27200#define CDECL __cdecl
Xiaohan Wang38e4ebb2022-01-19 06:57:43201#else // BUILDFLAG(IS_WIN)
jochen@chromium.org5a8d4ce2013-12-18 17:42:27202#define CDECL
Xiaohan Wang38e4ebb2022-01-19 06:57:43203#endif // BUILDFLAG(IS_WIN)
jochen@chromium.org5a8d4ce2013-12-18 17:42:27204#endif // !defined(CDECL)
205
skyostil@chromium.org2bc0c6992014-02-13 16:11:04206// Macro for hinting that an expression is likely to be false.
207#if !defined(UNLIKELY)
Vladimir Levin6b777712017-09-09 00:12:05208#if defined(COMPILER_GCC) || defined(__clang__)
skyostil@chromium.org2bc0c6992014-02-13 16:11:04209#define UNLIKELY(x) __builtin_expect(!!(x), 0)
210#else
211#define UNLIKELY(x) (x)
212#endif // defined(COMPILER_GCC)
213#endif // !defined(UNLIKELY)
214
palmer58184a8282016-11-08 19:15:39215#if !defined(LIKELY)
Vladimir Levin6b777712017-09-09 00:12:05216#if defined(COMPILER_GCC) || defined(__clang__)
Chris Palmerad4cb83f2016-11-18 20:02:25217#define LIKELY(x) __builtin_expect(!!(x), 1)
palmer58184a8282016-11-08 19:15:39218#else
219#define LIKELY(x) (x)
220#endif // defined(COMPILER_GCC)
221#endif // !defined(LIKELY)
222
jfbd81c1ce2016-04-05 20:50:35223// Compiler feature-detection.
jfba8dc9dd82016-04-06 20:20:31224// clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
225#if defined(__has_feature)
226#define HAS_FEATURE(FEATURE) __has_feature(FEATURE)
227#else
228#define HAS_FEATURE(FEATURE) 0
jfbd81c1ce2016-04-05 20:50:35229#endif
230
Alex Clarke23c6cf72018-11-21 13:22:27231#if defined(COMPILER_GCC)
232#define PRETTY_FUNCTION __PRETTY_FUNCTION__
233#elif defined(COMPILER_MSVC)
234#define PRETTY_FUNCTION __FUNCSIG__
235#else
236// See https://en.cppreference.com/w/c/language/function_definition#func
237#define PRETTY_FUNCTION __func__
238#endif
239
Henrique Ferreiro6daf71db2019-04-03 13:12:42240#if !defined(CPU_ARM_NEON)
241#if defined(__arm__)
242#if !defined(__ARMEB__) && !defined(__ARM_EABI__) && !defined(__EABI__) && \
243 !defined(__VFP_FP__) && !defined(_WIN32_WCE) && !defined(ANDROID)
244#error Chromium does not support middle endian architecture
245#endif
246#if defined(__ARM_NEON__)
247#define CPU_ARM_NEON 1
248#endif
249#endif // defined(__arm__)
250#endif // !defined(CPU_ARM_NEON)
251
252#if !defined(HAVE_MIPS_MSA_INTRINSICS)
253#if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5)
254#define HAVE_MIPS_MSA_INTRINSICS 1
255#endif
256#endif
257
Peter Kasting64c67dd2022-05-12 18:11:51258#if defined(__clang__) && HAS_ATTRIBUTE(uninitialized)
Vitaly Buka2b790762019-12-20 21:11:48259// Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for
260// the specified variable.
261// Library-wide alternative is
262// 'configs -= [ "//build/config/compiler:default_init_stack_vars" ]' in .gn
263// file.
264//
265// See "init_stack_vars" in build/config/compiler/BUILD.gn and
266// http://crbug.com/977230
267// "init_stack_vars" is enabled for non-official builds and we hope to enable it
268// in official build in 2020 as well. The flag writes fixed pattern into
269// uninitialized parts of all local variables. In rare cases such initialization
270// is undesirable and attribute can be used:
271// 1. Degraded performance
272// In most cases compiler is able to remove additional stores. E.g. if memory is
273// never accessed or properly initialized later. Preserved stores mostly will
274// not affect program performance. However if compiler failed on some
275// performance critical code we can get a visible regression in a benchmark.
276// 2. memset, memcpy calls
277// Compiler may replaces some memory writes with memset or memcpy calls. This is
278// not -ftrivial-auto-var-init specific, but it can happen more likely with the
279// flag. It can be a problem if code is not linked with C run-time library.
280//
281// Note: The flag is security risk mitigation feature. So in future the
282// attribute uses should be avoided when possible. However to enable this
283// mitigation on the most of the code we need to be less strict now and minimize
284// number of exceptions later. So if in doubt feel free to use attribute, but
285// please document the problem for someone who is going to cleanup it later.
286// E.g. platform, bot, benchmark or test name in patch description or next to
287// the attribute.
Peter Kastingf541f7782023-03-10 23:44:46288#define STACK_UNINITIALIZED [[clang::uninitialized]]
Vitaly Buka2b790762019-12-20 21:11:48289#else
290#define STACK_UNINITIALIZED
291#endif
292
Matthew Dentonbb0b03e2021-07-22 16:18:13293// Attribute "no_stack_protector" disables -fstack-protector for the specified
294// function.
295//
296// "stack_protector" is enabled on most POSIX builds. The flag adds a canary
297// to each stack frame, which on function return is checked against a reference
298// canary. If the canaries do not match, it's likely that a stack buffer
299// overflow has occurred, so immediately crashing will prevent exploitation in
300// many cases.
301//
302// In some cases it's desirable to remove this, e.g. on hot functions, or if
303// we have purposely changed the reference canary.
304#if defined(COMPILER_GCC) || defined(__clang__)
Peter Kasting64c67dd2022-05-12 18:11:51305#if HAS_ATTRIBUTE(__no_stack_protector__)
Stephan Hartmann4b456e72021-08-10 03:25:02306#define NO_STACK_PROTECTOR __attribute__((__no_stack_protector__))
Peter Kasting64c67dd2022-05-12 18:11:51307#else
Stephan Hartmann4b456e72021-08-10 03:25:02308#define NO_STACK_PROTECTOR __attribute__((__optimize__("-fno-stack-protector")))
309#endif
Matthew Dentonbb0b03e2021-07-22 16:18:13310#else
311#define NO_STACK_PROTECTOR
312#endif
313
Hans Wennborg12aea3e2020-04-14 15:29:00314// The ANALYZER_ASSUME_TRUE(bool arg) macro adds compiler-specific hints
315// to Clang which control what code paths are statically analyzed,
316// and is meant to be used in conjunction with assert & assert-like functions.
317// The expression is passed straight through if analysis isn't enabled.
318//
319// ANALYZER_SKIP_THIS_PATH() suppresses static analysis for the current
320// codepath and any other branching codepaths that might follow.
321#if defined(__clang_analyzer__)
322
323inline constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {
324 return false;
325}
326
327inline constexpr bool AnalyzerAssumeTrue(bool arg) {
328 // AnalyzerNoReturn() is invoked and analysis is terminated if |arg| is
329 // false.
330 return arg || AnalyzerNoReturn();
331}
332
George Burgess IVa09d235d2020-04-17 13:32:50333#define ANALYZER_ASSUME_TRUE(arg) ::AnalyzerAssumeTrue(!!(arg))
334#define ANALYZER_SKIP_THIS_PATH() static_cast<void>(::AnalyzerNoReturn())
Hans Wennborg12aea3e2020-04-14 15:29:00335
336#else // !defined(__clang_analyzer__)
337
338#define ANALYZER_ASSUME_TRUE(arg) (arg)
339#define ANALYZER_SKIP_THIS_PATH()
Hans Wennborg12aea3e2020-04-14 15:29:00340
341#endif // defined(__clang_analyzer__)
342
Zequan Wu9909f142021-02-10 03:26:00343// Use nomerge attribute to disable optimization of merging multiple same calls.
Peter Kasting64c67dd2022-05-12 18:11:51344#if defined(__clang__) && HAS_ATTRIBUTE(nomerge)
Zequan Wu9909f142021-02-10 03:26:00345#define NOMERGE [[clang::nomerge]]
346#else
347#define NOMERGE
348#endif
349
Jeremy Roman810d98d2021-04-06 16:46:07350// Marks a type as being eligible for the "trivial" ABI despite having a
351// non-trivial destructor or copy/move constructor. Such types can be relocated
352// after construction by simply copying their memory, which makes them eligible
353// to be passed in registers. The canonical example is std::unique_ptr.
354//
355// Use with caution; this has some subtle effects on constructor/destructor
356// ordering and will be very incorrect if the type relies on its address
357// remaining constant. When used as a function argument (by value), the value
358// may be constructed in the caller's stack frame, passed in a register, and
359// then used and destructed in the callee's stack frame. A similar thing can
360// occur when values are returned.
361//
362// TRIVIAL_ABI is not needed for types which have a trivial destructor and
363// copy/move constructors, such as base::TimeTicks and other POD.
364//
365// It is also not likely to be effective on types too large to be passed in one
366// or two registers on typical target ABIs.
367//
368// See also:
369// https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
370// https://libcxx.llvm.org/docs/DesignDocs/UniquePtrTrivialAbi.html
Peter Kasting64c67dd2022-05-12 18:11:51371#if defined(__clang__) && HAS_ATTRIBUTE(trivial_abi)
Jeremy Roman810d98d2021-04-06 16:46:07372#define TRIVIAL_ABI [[clang::trivial_abi]]
373#else
374#define TRIVIAL_ABI
375#endif
376
Lukasz Anforowicz3be38fbb2021-04-14 20:29:29377// Marks a member function as reinitializing a moved-from variable.
378// See also
379// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-use-after-move.html#reinitialization
Peter Kasting64c67dd2022-05-12 18:11:51380#if defined(__clang__) && HAS_ATTRIBUTE(reinitializes)
Lukasz Anforowicz3be38fbb2021-04-14 20:29:29381#define REINITIALIZES_AFTER_MOVE [[clang::reinitializes]]
382#else
383#define REINITIALIZES_AFTER_MOVE
384#endif
385
Benoit Lize5123edb2021-05-18 14:00:19386// Requires constant initialization. See constinit in C++20. Allows to rely on a
387// variable being initialized before execution, and not requiring a global
388// constructor.
Peter Kasting64c67dd2022-05-12 18:11:51389#if HAS_ATTRIBUTE(require_constant_initialization)
Benoit Lize5123edb2021-05-18 14:00:19390#define CONSTINIT __attribute__((require_constant_initialization))
Benoit Lize5123edb2021-05-18 14:00:19391#endif
Anton Bikineev6beb7102021-05-25 13:37:52392#if !defined(CONSTINIT)
393#define CONSTINIT
394#endif
Benoit Lize5123edb2021-05-18 14:00:19395
danakjceb17022022-02-11 23:52:01396#if defined(__clang__)
Daniel Cheng8ac305b2022-02-17 00:05:11397#define GSL_OWNER [[gsl::Owner]]
danakjceb17022022-02-11 23:52:01398#define GSL_POINTER [[gsl::Pointer]]
399#else
Jose Dapena Paz1183b142022-02-18 16:28:25400#define GSL_OWNER
danakjceb17022022-02-11 23:52:01401#define GSL_POINTER
402#endif
403
Daniel Chengf2c05382022-09-16 02:51:42404// Adds the "logically_const" tag to a symbol's mangled name. The "Mutable
405// Constants" check [1] detects instances of constants that aren't in .rodata,
406// e.g. due to a missing `const`. Using this tag suppresses the check for this
407// symbol, allowing it to live outside .rodata without a warning.
408//
409// [1]:
410// https://crsrc.org/c/docs/speed/binary_size/android_binary_size_trybot.md#Mutable-Constants
Anthony Vallee-Dubois9dbbbda32022-08-26 01:25:31411#if defined(COMPILER_GCC) || defined(__clang__)
412#define LOGICALLY_CONST [[gnu::abi_tag("logically_const")]]
413#else
414#define LOGICALLY_CONST
415#endif
416
agl@chromium.orgdd9afc0b2008-11-21 23:58:09417#endif // BASE_COMPILER_SPECIFIC_H_