diff options
author | Lei Zhang <thestig@chromium.org> | 2018-05-17 02:01:42 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-17 02:01:42 +0000 |
commit | db3c6cefceddf25c25f1205d7b633f09e873bf98 (patch) | |
tree | f79bf24591d3668da7c44190bbfae46c2c690f95 /third_party | |
parent | 1c0da4bf0f4235b50dade1c1d37fbd1f4421722d (diff) | |
download | pdfium-db3c6cefceddf25c25f1205d7b633f09e873bf98.tar.xz |
Update third_party/base/compiler_specific.h.
Import Chromium's base/compiler_specific.h from r537069.
Now that FALLTHROUGH is available via compiler_specific.h, remove
FX_FALLTHROUGH.
Change-Id: I8b9631a4f007673e10e0c26951dfd61e9dcada30
Reviewed-on: https://pdfium-review.googlesource.com/32639
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/base/compiler_specific.h | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/third_party/base/compiler_specific.h b/third_party/base/compiler_specific.h index 3dbd1abb33..57f7a93e59 100644 --- a/third_party/base/compiler_specific.h +++ b/third_party/base/compiler_specific.h @@ -43,22 +43,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_ @@ -68,7 +52,6 @@ #define MSVC_POP_WARNING() #define MSVC_DISABLE_OPTIMIZE() #define MSVC_ENABLE_OPTIMIZE() -#define NON_EXPORTED_BASE(code) code #endif // COMPILER_MSVC @@ -78,7 +61,7 @@ // 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: @@ -112,21 +95,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; @@ -207,7 +198,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) @@ -215,7 +206,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) @@ -230,4 +221,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_ |