[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:03 PDT 2025
https://github.com/lntue created https://github.com/llvm/llvm-project/pull/150264
Fixing bot failures: https://lab.llvm.org/buildbot/#/builders/10/builds/10025
>From 415c92c83ebe21034ceb13ecfdf8691d6f6e2066 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 23 Jul 2025 12:59:31 -0400
Subject: [PATCH] [libc] Fix problem with older compilers that do not have
__has_builtin.
---
libc/src/__support/CPP/type_traits/is_constant_evaluated.h | 4 ++++
libc/src/__support/macros/attributes.h | 6 ++++++
2 files changed, 10 insertions(+)
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
More information about the libc-commits
mailing list