Skip to content

Commit dbea6a7

Browse files
gchateletchencha3
authored andcommitted
[libc] Add is_constant_evaluated type_traits (llvm#86139)
This will replace `__builtin_is_constant_evaluated` in math_extras.h.
1 parent e944991 commit dbea6a7

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

libc/src/__support/CPP/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,24 @@ add_header_library(
103103
type_traits
104104
HDRS
105105
type_traits.h
106-
type_traits/always_false.h
107106
type_traits/add_lvalue_reference.h
108107
type_traits/add_pointer.h
109108
type_traits/add_rvalue_reference.h
109+
type_traits/always_false.h
110110
type_traits/bool_constant.h
111111
type_traits/conditional.h
112112
type_traits/decay.h
113113
type_traits/enable_if.h
114114
type_traits/false_type.h
115115
type_traits/integral_constant.h
116-
type_traits/invoke.h
117116
type_traits/invoke_result.h
117+
type_traits/invoke.h
118118
type_traits/is_arithmetic.h
119119
type_traits/is_array.h
120120
type_traits/is_base_of.h
121121
type_traits/is_class.h
122122
type_traits/is_const.h
123+
type_traits/is_constant_evaluated.h
123124
type_traits/is_convertible.h
124125
type_traits/is_destructible.h
125126
type_traits/is_enum.h

libc/src/__support/CPP/type_traits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "src/__support/CPP/type_traits/is_base_of.h"
2626
#include "src/__support/CPP/type_traits/is_class.h"
2727
#include "src/__support/CPP/type_traits/is_const.h"
28+
#include "src/__support/CPP/type_traits/is_constant_evaluated.h"
2829
#include "src/__support/CPP/type_traits/is_convertible.h"
2930
#include "src/__support/CPP/type_traits/is_destructible.h"
3031
#include "src/__support/CPP/type_traits/is_enum.h"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- is_constant_evaluated type_traits -----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
9+
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
10+
11+
#include "src/__support/macros/attributes.h"
12+
13+
namespace LIBC_NAMESPACE::cpp {
14+
15+
LIBC_INLINE constexpr bool is_constant_evaluated() {
16+
return __builtin_is_constant_evaluated();
17+
}
18+
19+
} // namespace LIBC_NAMESPACE::cpp
20+
21+
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ libc_support_library(
339339
"src/__support/CPP/type_traits/is_base_of.h",
340340
"src/__support/CPP/type_traits/is_class.h",
341341
"src/__support/CPP/type_traits/is_const.h",
342+
"src/__support/CPP/type_traits/is_constant_evaluated.h",
342343
"src/__support/CPP/type_traits/is_convertible.h",
343344
"src/__support/CPP/type_traits/is_destructible.h",
344345
"src/__support/CPP/type_traits/is_enum.h",
@@ -743,12 +744,12 @@ libc_support_library(
743744
deps = [
744745
":__support_common",
745746
":__support_cpp_bit",
746-
":__support_sign",
747747
":__support_cpp_type_traits",
748748
":__support_libc_assert",
749749
":__support_macros_attributes",
750750
":__support_macros_properties_types",
751751
":__support_math_extras",
752+
":__support_sign",
752753
":__support_uint128",
753754
],
754755
)

0 commit comments

Comments
 (0)