[libc-commits] [libc] [libc] Provide compiler version properties (PR #73344)
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Fri Nov 24 07:53:16 PST 2023
https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/73344
None
>From d2404a44eea1b253ca31c6cccf0c2155c1bf7615 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Fri, 24 Nov 2023 15:50:53 +0000
Subject: [PATCH] [libc] Provide compiler version properties
---
.../__support/macros/properties/compiler.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
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
More information about the libc-commits
mailing list