Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_COMPILER_SPECIFIC_H_ | 5 #ifndef BASE_COMPILER_SPECIFIC_H_ |
| 6 #define BASE_COMPILER_SPECIFIC_H_ | 6 #define BASE_COMPILER_SPECIFIC_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(COMPILER_MSVC) | 10 #if defined(COMPILER_MSVC) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 #elif COMPILER_MSVC && defined(NDEBUG) | 104 #elif COMPILER_MSVC && defined(NDEBUG) |
| 105 #define ALWAYS_INLINE __forceinline | 105 #define ALWAYS_INLINE __forceinline |
| 106 #else | 106 #else |
| 107 #define ALWAYS_INLINE inline | 107 #define ALWAYS_INLINE inline |
| 108 #endif | 108 #endif |
| 109 | 109 |
| 110 // Specify memory alignment for structs, classes, etc. | 110 // Specify memory alignment for structs, classes, etc. |
| 111 // Use like: | 111 // Use like: |
| 112 // class ALIGNAS(16) MyClass { ... } | 112 // class ALIGNAS(16) MyClass { ... } |
| 113 // ALIGNAS(16) int array[4]; | 113 // ALIGNAS(16) int array[4]; |
| 114 // | |
| 115 // In most places you can use the C++11 keyword "alignas", which is preferred. | |
| 116 // | |
| 117 // But compilers have trouble mixing __attribute__((...)) syntax with | |
| 118 // alignas(...) syntax. | |
| 119 // | |
| 120 // Doesn't work in clang or gcc: | |
| 121 // struct alignas(16) __attribute__((packed)) S { char c; }; | |
| 122 // Works in clang but not gcc: | |
| 123 // struct __attribute__((packed)) alignas(16) S2 { char c; }; | |
| 124 // Works in clang and gcc: | |
| 125 // struct alignas(16) S3 { char c; } __attribute__((packed)); | |
| 126 // | |
| 127 // There are also some attributes that must be specified *before* a class | |
| 128 // definition: visibility (used for exporting functions/classes) is one of | |
| 129 // these attributes. This means that it is not possible to have use alignas() | |
|
danakj
2017/06/12 18:32:10
typo: "to have use"
brettw
2017/06/12 22:22:15
I did this but haven't uploaded yet since I assume
| |
| 130 // with a class that is marked as exported. | |
| 114 #if defined(COMPILER_MSVC) | 131 #if defined(COMPILER_MSVC) |
| 115 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) | 132 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
| 116 #elif defined(COMPILER_GCC) | 133 #elif defined(COMPILER_GCC) |
| 117 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) | 134 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) |
| 118 #endif | 135 #endif |
| 119 | 136 |
| 120 // Return the byte alignment of the given type (available at compile time). | |
| 121 // Use like: | |
| 122 // ALIGNOF(int32_t) // this would be 4 | |
| 123 #if defined(COMPILER_MSVC) | |
| 124 #define ALIGNOF(type) __alignof(type) | |
| 125 #elif defined(COMPILER_GCC) | |
| 126 #define ALIGNOF(type) __alignof__(type) | |
| 127 #endif | |
| 128 | |
| 129 // Annotate a function indicating the caller must examine the return value. | 137 // Annotate a function indicating the caller must examine the return value. |
| 130 // Use like: | 138 // Use like: |
| 131 // int foo() WARN_UNUSED_RESULT; | 139 // int foo() WARN_UNUSED_RESULT; |
| 132 // To explicitly ignore a result, see |ignore_result()| in base/macros.h. | 140 // To explicitly ignore a result, see |ignore_result()| in base/macros.h. |
| 133 #undef WARN_UNUSED_RESULT | 141 #undef WARN_UNUSED_RESULT |
| 134 #if defined(COMPILER_GCC) || defined(__clang__) | 142 #if defined(COMPILER_GCC) || defined(__clang__) |
| 135 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) | 143 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| 136 #else | 144 #else |
| 137 #define WARN_UNUSED_RESULT | 145 #define WARN_UNUSED_RESULT |
| 138 #endif | 146 #endif |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 | 231 |
| 224 // Compiler feature-detection. | 232 // Compiler feature-detection. |
| 225 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension | 233 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension |
| 226 #if defined(__has_feature) | 234 #if defined(__has_feature) |
| 227 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) | 235 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) |
| 228 #else | 236 #else |
| 229 #define HAS_FEATURE(FEATURE) 0 | 237 #define HAS_FEATURE(FEATURE) 0 |
| 230 #endif | 238 #endif |
| 231 | 239 |
| 232 #endif // BASE_COMPILER_SPECIFIC_H_ | 240 #endif // BASE_COMPILER_SPECIFIC_H_ |
| OLD | NEW |