diff options
author | Jakub Pawlowski <jpawlowski@google.com> | 2017-04-05 09:22:29 -0700 |
---|---|---|
committer | Jakub Pawlowski <jpawlowski@google.com> | 2018-10-12 19:25:59 +0200 |
commit | e280f12834190c543be1ad4fddf6a642f65b998a (patch) | |
tree | a398a922d546c95123c3cc6e78091bef5378969b /base/compiler_specific.h | |
parent | 23b27ba5c54bf6368980117d91bc51c4495e2c50 (diff) | |
download | libchrome-e280f12834190c543be1ad4fddf6a642f65b998a.tar.gz |
Uprev libchrome to r576279 (1/many)
This patch brings the latest and greatest features of libchrome to
android. It contains ~2600 patches.
Reason for uprev: libbluetooth want to use some of the most recent
features avaliable.
Test: libchrome_test
Change-Id: Iccdec267948daab29e6328694f4c7d2f71ea26ca
Merged-In: Iccdec267948daab29e6328694f4c7d2f71ea26ca
Diffstat (limited to 'base/compiler_specific.h')
-rw-r--r-- | base/compiler_specific.h | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/base/compiler_specific.h b/base/compiler_specific.h index 327e3fabc0..a930f5d6cf 100644 --- a/base/compiler_specific.h +++ b/base/compiler_specific.h @@ -48,21 +48,6 @@ #define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off)) #define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on)) -// Allows exporting a class that inherits from a non-exported base class. -// This uses suppress instead of push/pop because the delimiter after the -// declaration (either "," or "{") has to be placed before the pop macro. -// -// Example usage: -// class EXPORT_API Foo : NON_EXPORTED_BASE(public Bar) { -// -// MSVC Compiler warning C4275: -// non dll-interface class 'Bar' used as base for dll-interface class 'Foo'. -// Note that this is intended to be used only when no access to the base class' -// static data is done through derived classes or inline methods. For more info, -// see http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx -#define NON_EXPORTED_BASE(code) MSVC_SUPPRESS_WARNING(4275) \ - code - #else // Not MSVC #define _Printf_format_string_ @@ -72,18 +57,16 @@ #define MSVC_POP_WARNING() #define MSVC_DISABLE_OPTIMIZE() #define MSVC_ENABLE_OPTIMIZE() -#define NON_EXPORTED_BASE(code) code #endif // COMPILER_MSVC - // Annotate a variable indicating it's ok if the variable is not used. // (Typically used to silence a compiler warning when the assignment // is important for some other reason.) // Use like: // int x = ...; // ALLOW_UNUSED_LOCAL(x); -#define ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0 +#define ALLOW_UNUSED_LOCAL(x) (void)x // Annotate a typedef or function indicating it's ok if it's not used. // Use like: @@ -117,21 +100,29 @@ // Use like: // class ALIGNAS(16) MyClass { ... } // ALIGNAS(16) int array[4]; +// +// In most places you can use the C++11 keyword "alignas", which is preferred. +// +// But compilers have trouble mixing __attribute__((...)) syntax with +// alignas(...) syntax. +// +// Doesn't work in clang or gcc: +// struct alignas(16) __attribute__((packed)) S { char c; }; +// Works in clang but not gcc: +// struct __attribute__((packed)) alignas(16) S2 { char c; }; +// Works in clang and gcc: +// struct alignas(16) S3 { char c; } __attribute__((packed)); +// +// There are also some attributes that must be specified *before* a class +// definition: visibility (used for exporting functions/classes) is one of +// these attributes. This means that it is not possible to use alignas() with a +// class that is marked as exported. #if defined(COMPILER_MSVC) #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) #elif defined(COMPILER_GCC) #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) #endif -// Return the byte alignment of the given type (available at compile time). -// Use like: -// ALIGNOF(int32_t) // this would be 4 -#if defined(COMPILER_MSVC) -#define ALIGNOF(type) __alignof(type) -#elif defined(COMPILER_GCC) -#define ALIGNOF(type) __alignof__(type) -#endif - // Annotate a function indicating the caller must examine the return value. // Use like: // int foo() WARN_UNUSED_RESULT; @@ -148,7 +139,7 @@ // |dots_param| is the one-based index of the "..." parameter. // For v*printf functions (which take a va_list), pass 0 for dots_param. // (This is undocumented but matches what the system C headers do.) -#if defined(COMPILER_GCC) +#if defined(COMPILER_GCC) || defined(__clang__) #define PRINTF_FORMAT(format_param, dots_param) \ __attribute__((format(printf, format_param, dots_param))) #else @@ -212,7 +203,7 @@ // Macro for hinting that an expression is likely to be false. #if !defined(UNLIKELY) -#if defined(COMPILER_GCC) +#if defined(COMPILER_GCC) || defined(__clang__) #define UNLIKELY(x) __builtin_expect(!!(x), 0) #else #define UNLIKELY(x) (x) @@ -220,7 +211,7 @@ #endif // !defined(UNLIKELY) #if !defined(LIKELY) -#if defined(COMPILER_GCC) +#if defined(COMPILER_GCC) || defined(__clang__) #define LIKELY(x) __builtin_expect(!!(x), 1) #else #define LIKELY(x) (x) @@ -235,4 +226,11 @@ #define HAS_FEATURE(FEATURE) 0 #endif +// Macro for telling -Wimplicit-fallthrough that a fallthrough is intentional. +#if defined(__clang__) +#define FALLTHROUGH [[clang::fallthrough]] +#else +#define FALLTHROUGH +#endif + #endif // BASE_COMPILER_SPECIFIC_H_ |