1 //===-- Compile time compiler detection -------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
10 #define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
12 // Example usage of compiler version checks
13 // #if defined(LIBC_COMPILER_CLANG_VER)
14 // # if LIBC_COMPILER_CLANG_VER < 1500
15 // # warning "Libc only supports Clang 15 and later"
17 // #elif defined(LIBC_COMPILER_GCC_VER)
18 // # if LIBC_COMPILER_GCC_VER < 1500
19 // # warning "Libc only supports GCC 15 and later"
21 // #elif defined(LIBC_COMPILER_MSC_VER)
22 // # if LIBC_COMPILER_MSC_VER < 1930
23 // # warning "Libc only supports Visual Studio 2022 RTW (17.0) and later"
27 #if defined(__clang__)
28 #define LIBC_COMPILER_IS_CLANG
29 #define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
32 #if defined(__GNUC__) && !defined(__clang__)
33 #define LIBC_COMPILER_IS_GCC
34 #define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
38 #define LIBC_COMPILER_IS_MSC
39 // https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
40 #define LIBC_COMPILER_MSC_VER (_MSC_VER)
43 #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H