Skip to content

Commit ee5749b

Browse files
authored
[libc] Provide compiler version properties (#73344)
This will be used to support conditional compilation based on compiler version. We adopt the same convention as [libc++](https://github.com/llvm/llvm-project/blob/main/libcxx/include/__config) - thx @legrosbuffle for the suggestion! Usage: ``` #if defined(LIBC_COMPILER_CLANG_VER) # if LIBC_COMPILER_CLANG_VER < 1500 # warning "Libc only supports Clang 15 and later" # endif #elif defined(LIBC_COMPILER_GCC_VER) # if LIBC_COMPILER_GCC_VER < 1500 # warning "Libc only supports GCC 15 and later" # endif #elif defined(LIBC_COMPILER_MSC_VER) # if LIBC_COMPILER_MSC_VER < 1930 # warning "Libc only supports Visual Studio 2022 RTW (17.0) and later" # endif #endif ```
1 parent bd8f106 commit ee5749b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

libc/src/__support/macros/properties/compiler.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,35 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
1010
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
1111

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"
16+
// # endif
17+
// #elif defined(LIBC_COMPILER_GCC_VER)
18+
// # if LIBC_COMPILER_GCC_VER < 1500
19+
// # warning "Libc only supports GCC 15 and later"
20+
// # endif
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"
24+
// # endif
25+
// #endif
26+
1227
#if defined(__clang__)
1328
#define LIBC_COMPILER_IS_CLANG
29+
#define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
1430
#endif
1531

1632
#if defined(__GNUC__) && !defined(__clang__)
1733
#define LIBC_COMPILER_IS_GCC
34+
#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
1835
#endif
1936

2037
#if defined(_MSC_VER)
2138
#define LIBC_COMPILER_IS_MSC
39+
// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
40+
#define LIBC_COMPILER_MSC_VER (_MSC_VER)
2241
#endif
2342

2443
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H

0 commit comments

Comments
 (0)