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

via libc-commits libc-commits at lists.llvm.org
Wed Mar 25 20:21:58 PDT 2026


Author: lntue
Date: 2026-03-25T23:21:53-04:00
New Revision: 5a2fedf91d9dd9e834809677e0213865a3ad1740

URL: https://github.com/llvm/llvm-project/commit/5a2fedf91d9dd9e834809677e0213865a3ad1740
DIFF: https://github.com/llvm/llvm-project/commit/5a2fedf91d9dd9e834809677e0213865a3ad1740.diff

LOG: [libc][msvc] Re-enable __builtin_is_constant_evaluated for MSVC. (#188663)

Added: 
    

Modified: 
    libc/src/__support/CPP/type_traits/is_constant_evaluated.h
    libc/src/__support/macros/attributes.h
    libc/src/__support/macros/config.h

Removed: 
    


################################################################################
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