Skip to content

[libc] Add is_constant_evaluated type_traits #86139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libc/src/__support/CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,24 @@ add_header_library(
type_traits
HDRS
type_traits.h
type_traits/always_false.h
type_traits/add_lvalue_reference.h
type_traits/add_pointer.h
type_traits/add_rvalue_reference.h
type_traits/always_false.h
type_traits/bool_constant.h
type_traits/conditional.h
type_traits/decay.h
type_traits/enable_if.h
type_traits/false_type.h
type_traits/integral_constant.h
type_traits/invoke.h
type_traits/invoke_result.h
type_traits/invoke.h
type_traits/is_arithmetic.h
type_traits/is_array.h
type_traits/is_base_of.h
type_traits/is_class.h
type_traits/is_const.h
type_traits/is_constant_evaluated.h
type_traits/is_convertible.h
type_traits/is_destructible.h
type_traits/is_enum.h
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/CPP/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "src/__support/CPP/type_traits/is_base_of.h"
#include "src/__support/CPP/type_traits/is_class.h"
#include "src/__support/CPP/type_traits/is_const.h"
#include "src/__support/CPP/type_traits/is_constant_evaluated.h"
#include "src/__support/CPP/type_traits/is_convertible.h"
#include "src/__support/CPP/type_traits/is_destructible.h"
#include "src/__support/CPP/type_traits/is_enum.h"
Expand Down
21 changes: 21 additions & 0 deletions libc/src/__support/CPP/type_traits/is_constant_evaluated.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- is_constant_evaluated type_traits -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H

#include "src/__support/macros/attributes.h"

namespace LIBC_NAMESPACE::cpp {

LIBC_INLINE constexpr bool is_constant_evaluated() {
return __builtin_is_constant_evaluated();
}

} // namespace LIBC_NAMESPACE::cpp

#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
3 changes: 2 additions & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ libc_support_library(
"src/__support/CPP/type_traits/is_base_of.h",
"src/__support/CPP/type_traits/is_class.h",
"src/__support/CPP/type_traits/is_const.h",
"src/__support/CPP/type_traits/is_constant_evaluated.h",
"src/__support/CPP/type_traits/is_convertible.h",
"src/__support/CPP/type_traits/is_destructible.h",
"src/__support/CPP/type_traits/is_enum.h",
Expand Down Expand Up @@ -743,12 +744,12 @@ libc_support_library(
deps = [
":__support_common",
":__support_cpp_bit",
":__support_sign",
":__support_cpp_type_traits",
":__support_libc_assert",
":__support_macros_attributes",
":__support_macros_properties_types",
":__support_math_extras",
":__support_sign",
":__support_uint128",
],
)
Expand Down