[libc-commits] [libc] [libc] Provide compiler version properties (PR #73344)
via libc-commits
libc-commits at lists.llvm.org
Fri Nov 24 07:53:46 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Guillaume Chatelet (gchatelet)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/73344.diff
1 Files Affected:
- (modified) libc/src/__support/macros/properties/compiler.h (+19)
``````````diff
diff --git a/libc/src/__support/macros/properties/compiler.h b/libc/src/__support/macros/properties/compiler.h
index a7a2822bf6a14a6..b9ec0dd1defb9df 100644
--- a/libc/src/__support/macros/properties/compiler.h
+++ b/libc/src/__support/macros/properties/compiler.h
@@ -9,16 +9,35 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
+// Example usage of compiler version checks
+// #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
+
#if defined(__clang__)
#define LIBC_COMPILER_IS_CLANG
+#define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
#endif
#if defined(__GNUC__) && !defined(__clang__)
#define LIBC_COMPILER_IS_GCC
+#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
#endif
#if defined(_MSC_VER)
#define LIBC_COMPILER_IS_MSC
+// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
+#define LIBC_COMPILER_MSC_VER (_MSC_VER)
#endif
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
``````````
</details>
https://github.com/llvm/llvm-project/pull/73344
More information about the libc-commits
mailing list