[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:03:15 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: lntue

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/188663.diff


3 Files Affected:

- (modified) libc/src/__support/CPP/type_traits/is_constant_evaluated.h (+1-1) 
- (modified) libc/src/__support/macros/attributes.h (+6-1) 
- (modified) libc/src/__support/macros/config.h (+2) 


``````````diff
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__

``````````

</details>


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


More information about the libc-commits mailing list