DebugServer2
Loading...
Searching...
No Matches
CompilerSupport.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Base.h"
14
15#if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
16#if defined(PLATFORM_MINGW)
17// MinGW uses printf wrappers to provide standard format string behavior on
18// Windows. We need to use __MINGW_PRINTF_FORMAT as GCC assumes MS style printf
19// arguments with `__format__(printf, ...)`.
20#define DS2_ATTRIBUTE_PRINTF(FORMAT, START) \
21 __attribute__((__format__(__MINGW_PRINTF_FORMAT, FORMAT, START)))
22#else
23#define DS2_ATTRIBUTE_PRINTF(FORMAT, START) \
24 __attribute__((__format__(printf, FORMAT, START)))
25#endif
26#else
27#define DS2_ATTRIBUTE_PRINTF(FORMAT, START)
28#endif
29
30#if defined(COMPILER_MSVC)
31#define DS2_ATTRIBUTE_PACKED "DS2_ATTRIBUTE_PACKED not implemented on MSVC"
32#elif defined(COMPILER_GCC) || defined(COMPILER_CLANG)
33#define DS2_ATTRIBUTE_PACKED __attribute__((__packed__))
34#endif
35
36#if defined(COMPILER_MSVC)
37#define DS2_ATTRIBUTE_ALIGNED "DS2_ATTRIBUTE_ALIGNED not implemented on MSVC"
38#elif defined(COMPILER_GCC) || defined(COMPILER_CLANG)
39#define DS2_ATTRIBUTE_ALIGNED(SIZE) __attribute__((__aligned__(SIZE)))
40#endif
41
42#if defined(COMPILER_MSVC)
43#define DS2_UNREACHABLE() __assume(0)
44#elif defined(COMPILER_GCC) || defined(COMPILER_CLANG)
45#define DS2_UNREACHABLE() __builtin_unreachable()
46#else
47#include <cstdlib>
48#define DS2_UNREACHABLE() abort()
49#endif