1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // IWYU pragma: private, include "chre_api/chre.h" 18 // IWYU pragma: friend chre/.*\.h 19 20 #ifndef CHRE_TOOLCHAIN_H_ 21 #define CHRE_TOOLCHAIN_H_ 22 23 /** 24 * @file 25 * Compiler/build toolchain-specific macros used by the CHRE API 26 */ 27 28 #if defined(__GNUC__) || defined(__clang__) 29 // For GCC and clang 30 31 #define CHRE_DEPRECATED(message) \ 32 __attribute__((deprecated(message))) 33 34 // Indicates that the function does not return (i.e. abort). 35 #define CHRE_NO_RETURN __attribute__((noreturn)) 36 37 // Enable printf-style compiler warnings for mismatched format string and args 38 #define CHRE_PRINTF_ATTR(formatPos, argStart) \ 39 __attribute__((format(printf, formatPos, argStart))) 40 41 #define CHRE_BUILD_ERROR(message) CHRE_DO_PRAGMA(GCC error message) 42 #define CHRE_DO_PRAGMA(message) _Pragma(#message) 43 44 // Marks a function as malloc-like, for optimizations with the return pointer 45 #define CHRE_MALLOC_ATTR __attribute__((__malloc__)) 46 47 #elif defined(__ICCARM__) || defined(__CC_ARM) 48 // For IAR ARM and Keil MDK-ARM compilers 49 50 #define CHRE_PRINTF_ATTR(formatPos, argStart) 51 52 #define CHRE_DEPRECATED(message) 53 54 #define CHRE_NO_RETURN 55 56 #define CHRE_MALLOC_ATTR 57 58 #elif defined(_MSC_VER) 59 // For Microsoft Visual Studio 60 61 #define CHRE_PRINTF_ATTR(formatPos, argStart) 62 63 #define CHRE_DEPRECATED(message) 64 65 #define CHRE_NO_RETURN 66 67 #define CHRE_MALLOC_ATTR 68 69 #else // if !defined(__GNUC__) && !defined(__clang__) 70 71 #error Need to add support for new compiler 72 73 #endif 74 75 // For platforms that don't support error pragmas, utilize the best method of 76 // showing an error depending on the platform support. 77 #ifndef CHRE_BUILD_ERROR 78 #ifdef __cplusplus // C++17 or greater assumed 79 #define CHRE_BUILD_ERROR(message) static_assert(0, message) 80 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L 81 #define CHRE_BUILD_ERROR(message) _Static_assert(0, message) 82 #else 83 #define CHRE_BUILD_ERROR(message) char buildError[-1] = message 84 #endif 85 #endif 86 87 #endif // CHRE_TOOLCHAIN_H_ 88