|
181 | 181 | #define ABSL_PREDICT_TRUE(x) (x)
|
182 | 182 | #endif
|
183 | 183 |
|
184 |
| -// Platform and compilation mode dependent implementation of ABSL_ASSUME. |
185 |
| -#if !defined(NDEBUG) |
186 |
| -#define ABSL_INTERNAL_ASSUME(cond) assert(cond) |
187 |
| -#elif ABSL_HAVE_BUILTIN(__builtin_assume) |
188 |
| -#define ABSL_INTERNAL_ASSUME(cond) __builtin_assume(cond) |
189 |
| -#elif defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_unreachable) |
190 |
| -#define ABSL_INTERNAL_ASSUME(cond) \ |
191 |
| - do { \ |
192 |
| - if (!(cond)) __builtin_unreachable(); \ |
193 |
| - } while (0) |
194 |
| -#elif defined(_MSC_VER) |
195 |
| -#define ABSL_INTERNAL_ASSUME(cond) __assume(cond) |
196 |
| -#else |
197 |
| -#define ABSL_INTERNAL_ASSUME(cond) \ |
198 |
| - do { \ |
199 |
| - static_cast<void>(false && (cond)); \ |
200 |
| - } while (0) |
201 |
| -#endif |
202 |
| - |
203 | 184 | // ABSL_ASSUME(cond)
|
| 185 | +// |
204 | 186 | // Informs the compiler that a condition is always true and that it can assume
|
205 |
| -// it to be true for optimization purposes. The call has undefined behavior if |
206 |
| -// the condition is false. |
| 187 | +// it to be true for optimization purposes. |
| 188 | +// |
| 189 | +// WARNING: If the condition is false, the program can produce undefined and |
| 190 | +// potentially dangerous behavior. |
| 191 | +// |
207 | 192 | // In !NDEBUG mode, the condition is checked with an assert().
|
| 193 | +// |
208 | 194 | // NOTE: The expression must not have side effects, as it may only be evaluated
|
209 |
| -// in some compilation modes and not others. |
| 195 | +// in some compilation modes and not others. Some compilers may issue a warning |
| 196 | +// if the compiler cannot prove the expression has no side effects. For example, |
| 197 | +// the expression should not use a function call since the compiler cannot prove |
| 198 | +// that a function call does not have side effects. |
210 | 199 | //
|
211 | 200 | // Example:
|
212 | 201 | //
|
|
216 | 205 | // // assumption specified above.
|
217 | 206 | // int y = x / 16;
|
218 | 207 | //
|
219 |
| -#define ABSL_ASSUME(cond) ABSL_INTERNAL_ASSUME(cond) |
| 208 | +#if !defined(NDEBUG) |
| 209 | +#define ABSL_ASSUME(cond) assert(cond) |
| 210 | +#elif ABSL_HAVE_BUILTIN(__builtin_assume) |
| 211 | +#define ABSL_ASSUME(cond) __builtin_assume(cond) |
| 212 | +#elif defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_unreachable) |
| 213 | +#define ABSL_ASSUME(cond) \ |
| 214 | + do { \ |
| 215 | + if (!(cond)) __builtin_unreachable(); \ |
| 216 | + } while (0) |
| 217 | +#elif defined(_MSC_VER) |
| 218 | +#define ABSL_ASSUME(cond) __assume(cond) |
| 219 | +#else |
| 220 | +#define ABSL_ASSUME(cond) \ |
| 221 | + do { \ |
| 222 | + static_cast<void>(false && (cond)); \ |
| 223 | + } while (0) |
| 224 | +#endif |
220 | 225 |
|
221 | 226 | // ABSL_INTERNAL_UNIQUE_SMALL_NAME(cond)
|
222 | 227 | // This macro forces small unique name on a static file level symbols like
|
|
0 commit comments