16d528ed9Sopenharmony_ci// Copyright (c) 2012 The Chromium Authors. All rights reserved. 26d528ed9Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 36d528ed9Sopenharmony_ci// found in the LICENSE file. 46d528ed9Sopenharmony_ci 56d528ed9Sopenharmony_ci#ifndef BASE_COMPILER_SPECIFIC_H_ 66d528ed9Sopenharmony_ci#define BASE_COMPILER_SPECIFIC_H_ 76d528ed9Sopenharmony_ci 86d528ed9Sopenharmony_ci#include "util/build_config.h" 96d528ed9Sopenharmony_ci 106d528ed9Sopenharmony_ci#if defined(COMPILER_MSVC) 116d528ed9Sopenharmony_ci 126d528ed9Sopenharmony_ci// For _Printf_format_string_. 136d528ed9Sopenharmony_ci#include <sal.h> 146d528ed9Sopenharmony_ci 156d528ed9Sopenharmony_ci#else // Not MSVC 166d528ed9Sopenharmony_ci 176d528ed9Sopenharmony_ci#define _Printf_format_string_ 186d528ed9Sopenharmony_ci 196d528ed9Sopenharmony_ci#endif // COMPILER_MSVC 206d528ed9Sopenharmony_ci 216d528ed9Sopenharmony_ci#if defined(COMPILER_GCC) && defined(NDEBUG) 226d528ed9Sopenharmony_ci#define ALWAYS_INLINE inline __attribute__((__always_inline__)) 236d528ed9Sopenharmony_ci#elif defined(COMPILER_MSVC) && defined(NDEBUG) 246d528ed9Sopenharmony_ci#define ALWAYS_INLINE __forceinline 256d528ed9Sopenharmony_ci#else 266d528ed9Sopenharmony_ci#define ALWAYS_INLINE inline 276d528ed9Sopenharmony_ci#endif 286d528ed9Sopenharmony_ci 296d528ed9Sopenharmony_ci// Tell the compiler a function is using a printf-style format string. 306d528ed9Sopenharmony_ci// |format_param| is the one-based index of the format string parameter; 316d528ed9Sopenharmony_ci// |dots_param| is the one-based index of the "..." parameter. 326d528ed9Sopenharmony_ci// For v*printf functions (which take a va_list), pass 0 for dots_param. 336d528ed9Sopenharmony_ci// (This is undocumented but matches what the system C headers do.) 346d528ed9Sopenharmony_ci#if defined(COMPILER_GCC) || defined(__clang__) 356d528ed9Sopenharmony_ci#define PRINTF_FORMAT(format_param, dots_param) \ 366d528ed9Sopenharmony_ci __attribute__((format(printf, format_param, dots_param))) 376d528ed9Sopenharmony_ci#else 386d528ed9Sopenharmony_ci#define PRINTF_FORMAT(format_param, dots_param) 396d528ed9Sopenharmony_ci#endif 406d528ed9Sopenharmony_ci 416d528ed9Sopenharmony_ci// Macro for hinting that an expression is likely to be false. 426d528ed9Sopenharmony_ci#if !defined(UNLIKELY) 436d528ed9Sopenharmony_ci#if defined(COMPILER_GCC) || defined(__clang__) 446d528ed9Sopenharmony_ci#define UNLIKELY(x) __builtin_expect(!!(x), 0) 456d528ed9Sopenharmony_ci#else 466d528ed9Sopenharmony_ci#define UNLIKELY(x) (x) 476d528ed9Sopenharmony_ci#endif // defined(COMPILER_GCC) 486d528ed9Sopenharmony_ci#endif // !defined(UNLIKELY) 496d528ed9Sopenharmony_ci 506d528ed9Sopenharmony_ci#if !defined(LIKELY) 516d528ed9Sopenharmony_ci#if defined(COMPILER_GCC) || defined(__clang__) 526d528ed9Sopenharmony_ci#define LIKELY(x) __builtin_expect(!!(x), 1) 536d528ed9Sopenharmony_ci#else 546d528ed9Sopenharmony_ci#define LIKELY(x) (x) 556d528ed9Sopenharmony_ci#endif // defined(COMPILER_GCC) 566d528ed9Sopenharmony_ci#endif // !defined(LIKELY) 576d528ed9Sopenharmony_ci 586d528ed9Sopenharmony_ci// Macro for telling -Wimplicit-fallthrough that a fallthrough is intentional. 596d528ed9Sopenharmony_ci#if __cplusplus >= 201703L 606d528ed9Sopenharmony_ci#define FALLTHROUGH [[fallthrough]] 616d528ed9Sopenharmony_ci#elif defined(__clang__) 626d528ed9Sopenharmony_ci#define FALLTHROUGH [[clang::fallthrough]] 636d528ed9Sopenharmony_ci#else 646d528ed9Sopenharmony_ci#define FALLTHROUGH 656d528ed9Sopenharmony_ci#endif 666d528ed9Sopenharmony_ci 676d528ed9Sopenharmony_ci#endif // BASE_COMPILER_SPECIFIC_H_ 68