[libc-commits] [libc] [libc] Fix problem with older compilers that do not have __has_builtin. (PR #150264)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 23 10:02:34 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (lntue)

<details>
<summary>Changes</summary>

Fixing bot failures: https://lab.llvm.org/buildbot/#/builders/10/builds/10025

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


2 Files Affected:

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


``````````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 0bb2d0806cb0d..9339af46d6762 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,11 @@ namespace LIBC_NAMESPACE_DECL {
 namespace cpp {
 
 LIBC_INLINE constexpr bool is_constant_evaluated() {
+#if LIBC_HAS_BUILTIN(__builtin_is_constant_evaluated)
   return __builtin_is_constant_evaluated();
+#else
+  return false;
+#endif
 }
 
 } // namespace cpp
diff --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h
index c6474673de85a..62b0f7c3d6155 100644
--- a/libc/src/__support/macros/attributes.h
+++ b/libc/src/__support/macros/attributes.h
@@ -48,4 +48,10 @@
 #define LIBC_PREFERED_TYPE(TYPE)
 #endif
 
+#ifndef __has_builtin
+#define LIBC_HAS_BUILTIN(X) 0
+#else
+#define LIBC_HAS_BUILTIN(X) __has_builtin(X)
+#endif
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H

``````````

</details>


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


More information about the libc-commits mailing list