[libc-commits] [libc] [libc][msvc] Re-enable __builtin_is_constant_evaluated for MSVC. (PR #188663)

via libc-commits libc-commits at lists.llvm.org
Wed Mar 25 19:02:41 PDT 2026


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/188663

None

>From c3c09db8833ff84379bbcedcc08c4118ec328248 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 25 Mar 2026 22:01:08 -0400
Subject: [PATCH] [libc][msvc] Re-enable __builtin_is_constant_evaluated for
 MSVC.

---
 libc/src/__support/CPP/type_traits/is_constant_evaluated.h | 2 +-
 libc/src/__support/macros/attributes.h                     | 7 ++++++-
 libc/src/__support/macros/config.h                         | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libc/src/__support/CPP/type_traits/is_constant_evaluated.h b/libc/src/__support/CPP/type_traits/is_constant_evaluated.h
index 65adbc1ae0ed9..dee3f39b7bc97 100644
--- a/libc/src/__support/CPP/type_traits/is_constant_evaluated.h
+++ b/libc/src/__support/CPP/type_traits/is_constant_evaluated.h
@@ -15,7 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
 namespace cpp {
 
 LIBC_INLINE constexpr bool is_constant_evaluated() {
-#if __has_builtin(__builtin_is_constant_evaluated)
+#if LIBC_HAS_BUILTIN_IS_CONSTANT_EVALUATED
   return __builtin_is_constant_evaluated();
 #else
   return false;
diff --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h
index 6908c365e4776..cc28e7e7cbcf1 100644
--- a/libc/src/__support/macros/attributes.h
+++ b/libc/src/__support/macros/attributes.h
@@ -29,13 +29,18 @@
 #define LIBC_INLINE_ASM __asm__ __volatile__
 #define LIBC_UNUSED __attribute__((unused))
 
+#ifndef LIBC_HAS_BUILTIN_IS_CONSTANT_EVALUATED
+#define LIBC_HAS_BUILTIN_IS_CONSTANT_EVALUATED                                 \
+  (__has_builtin(__builtin_is_constant_evaluated))
+#endif // LIBC_HAS_BUILTIN_IS_CONSTANT_EVALUATED
+
 // TODO: Remove the macro once Clang/LLVM bump their minimum compilers' version.
 // The reason for indirection is GCC is known to fail with constexpr qualified
 // functions that doesn't produce constant expression. This avoids it by using
 // LIBC_ENABLE_CONSTEXPR as a flag to control whether the function should be
 // constexpr qualified or not.
 #if LIBC_ENABLE_CONSTEXPR &&                                                   \
-    (__has_builtin(__builtin_is_constant_evaluated) ||                         \
+    (LIBC_HAS_BUILTIN_IS_CONSTANT_EVALUATED ||                                 \
      (defined(LIBC_COMPILER_IS_GCC) && (LIBC_COMPILER_GCC_VER >= 900)) ||      \
      (defined(LIBC_COMPILER_IS_CLANG) && LIBC_COMPILER_CLANG_VER >= 1100))
 #define LIBC_HAS_CONSTANT_EVALUATION
diff --git a/libc/src/__support/macros/config.h b/libc/src/__support/macros/config.h
index a876a39069b01..d9c80423f499d 100644
--- a/libc/src/__support/macros/config.h
+++ b/libc/src/__support/macros/config.h
@@ -48,6 +48,8 @@
 
 #define __builtin_prefetch(X, Y, Z)
 
+#define LIBC_HAS_BUILTIN_IS_CONSTANT_EVALUATED 1
+
 #endif // LIBC_COMPILER_IS_MSVC
 
 #ifdef __clang__



More information about the libc-commits mailing list