// Copyright 2008 The Chromium Authors. All rights reserved.
|
// Use of this source code is governed by a BSD-style license that can be
|
// found in the LICENSE file.
|
|
#ifndef MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_
|
#define MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_
|
|
#include "build/build_config.h"
|
|
// 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
|
|
// Annotate a typedef or function indicating it's ok if it's not used.
|
// Use like:
|
// typedef Foo Bar ALLOW_UNUSED_TYPE;
|
#if defined(COMPILER_GCC)
|
#define ALLOW_UNUSED_TYPE __attribute__((unused))
|
#else
|
#define ALLOW_UNUSED_TYPE
|
#endif
|
|
// Specify memory alignment for structs, classes, etc.
|
// Use like:
|
// class ALIGNAS(16) MyClass { ... }
|
// ALIGNAS(16) int array[4];
|
#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
|
|
#if defined(COMPILER_MSVC)
|
#define WARN_UNUSED_RESULT
|
#else
|
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
#endif
|
|
#if defined(COMPILER_MSVC)
|
#define PRINTF_FORMAT(format_param, dots_param)
|
#else
|
#define PRINTF_FORMAT(format_param, dots_param) \
|
__attribute__((format(printf, format_param, dots_param)))
|
#endif
|
|
// Sanitizers annotations.
|
#if defined(__has_attribute)
|
#if __has_attribute(no_sanitize)
|
#define NO_SANITIZE(what) __attribute__((no_sanitize(what)))
|
#endif
|
#endif
|
#if !defined(NO_SANITIZE)
|
#define NO_SANITIZE(what)
|
#endif
|
|
// DISABLE_CFI_ICALL -- Disable Control Flow Integrity indirect call checks.
|
#if defined(OS_WIN)
|
// Windows also needs __declspec(guard(nocf)).
|
#define DISABLE_CFI_ICALL NO_SANITIZE("cfi-icall") __declspec(guard(nocf))
|
#else
|
#define DISABLE_CFI_ICALL NO_SANITIZE("cfi-icall")
|
#endif
|
|
// Compiler feature-detection.
|
// clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
|
#if defined(__has_feature)
|
#define HAS_FEATURE(FEATURE) __has_feature(FEATURE)
|
#else
|
#define HAS_FEATURE(FEATURE) 0
|
#endif
|
|
// Macro for telling -Wimplicit-fallthrough that a fallthrough is intentional.
|
#if __cplusplus >= 201703L // C++17
|
#define FALLTHROUGH [[fallthrough]]
|
#elif defined(__clang__)
|
#define FALLTHROUGH [[clang::fallthrough]]
|
#else
|
#define FALLTHROUGH
|
#endif
|
|
#endif // MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_
|