From 65f6b92b1b7741d13f27928aecd3d444375fbcf8 Mon Sep 17 00:00:00 2001 From: Tue Ly Date: Wed, 23 Jul 2025 21:06:33 +0000 Subject: [PATCH] [libc] Add support for __builtin_is_constant_evaluated for GCC 9+. --- libc/src/__support/CPP/type_traits/is_constant_evaluated.h | 4 ---- libc/src/__support/RPC/rpc_server.h | 6 +++++- libc/src/__support/macros/attributes.h | 6 ------ 3 files changed, 5 insertions(+), 11 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 9339af46d6762..0bb2d0806cb0d 100644 --- a/libc/src/__support/CPP/type_traits/is_constant_evaluated.h +++ b/libc/src/__support/CPP/type_traits/is_constant_evaluated.h @@ -15,11 +15,7 @@ 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/RPC/rpc_server.h b/libc/src/__support/RPC/rpc_server.h index dc3d8030caa47..beea4dd975ea7 100644 --- a/libc/src/__support/RPC/rpc_server.h +++ b/libc/src/__support/RPC/rpc_server.h @@ -15,13 +15,17 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_RPC_RPC_SERVER_H #define LLVM_LIBC_SRC___SUPPORT_RPC_RPC_SERVER_H +#include "src/__support/macros/properties/compiler.h" + // Workaround for missing __has_builtin in < GCC 10. #ifndef __has_builtin #define __has_builtin(x) 0 #endif // Workaround for missing __builtin_is_constant_evaluated in < GCC 10. -#ifndef __builtin_is_constant_evaluated +// Also this builtin is defined for GCC 9. +#if !(__has_builtin(__builtin_is_constant_evaluated) || \ + (defined(LIBC_COMPILER_IS_GCC) && (LIBC_COMPILER_GCC_VER >= 900))) #define __builtin_is_constant_evaluated(x) 0 #endif diff --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h index 62b0f7c3d6155..c6474673de85a 100644 --- a/libc/src/__support/macros/attributes.h +++ b/libc/src/__support/macros/attributes.h @@ -48,10 +48,4 @@ #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