[llvm] 773caac - [ADT] Use llvm::to_underlying (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 20:03:27 PDT 2023
Author: Kazu Hirata
Date: 2023-10-31T20:03:20-07:00
New Revision: 773caac71123fec3367b533e6aecff067dea9718
URL: https://github.com/llvm/llvm-project/commit/773caac71123fec3367b533e6aecff067dea9718
DIFF: https://github.com/llvm/llvm-project/commit/773caac71123fec3367b533e6aecff067dea9718.diff
LOG: [ADT] Use llvm::to_underlying (NFC)
Added:
Modified:
llvm/include/llvm/ADT/BitmaskEnum.h
llvm/include/llvm/ADT/FoldingSet.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/BitmaskEnum.h b/llvm/include/llvm/ADT/BitmaskEnum.h
index 976fddde725f0cd..5fe724d80c3302e 100644
--- a/llvm/include/llvm/ADT/BitmaskEnum.h
+++ b/llvm/include/llvm/ADT/BitmaskEnum.h
@@ -13,6 +13,7 @@
#include <type_traits>
#include <utility>
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/Support/MathExtras.h"
/// LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can
@@ -125,7 +126,7 @@ template <typename E> constexpr std::underlying_type_t<E> Mask() {
/// Check that Val is in range for E, and return Val cast to E's underlying
/// type.
template <typename E> constexpr std::underlying_type_t<E> Underlying(E Val) {
- auto U = static_cast<std::underlying_type_t<E>>(Val);
+ auto U = llvm::to_underlying(Val);
assert(U >= 0 && "Negative enum values are not allowed.");
assert(U <= Mask<E>() && "Enum value too large (or largest val too small?)");
return U;
@@ -181,9 +182,8 @@ E &operator^=(E &LHS, E RHS) {
// Enable bitmask enums in namespace ::llvm and all nested namespaces.
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>>
-constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth(uint64_t{
- static_cast<std::underlying_type_t<E>>(
- E::LLVM_BITMASK_LARGEST_ENUMERATOR)});
+constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth(
+ uint64_t{llvm::to_underlying(E::LLVM_BITMASK_LARGEST_ENUMERATOR)});
} // namespace llvm
diff --git a/llvm/include/llvm/ADT/FoldingSet.h b/llvm/include/llvm/ADT/FoldingSet.h
index 237668921cbb273..f82eabd5044b22f 100644
--- a/llvm/include/llvm/ADT/FoldingSet.h
+++ b/llvm/include/llvm/ADT/FoldingSet.h
@@ -17,6 +17,7 @@
#define LLVM_ADT_FOLDINGSET_H
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/Allocator.h"
@@ -832,7 +833,7 @@ struct FoldingSetTrait<std::pair<T1, T2>> {
template <typename T>
struct FoldingSetTrait<T, std::enable_if_t<std::is_enum<T>::value>> {
static void Profile(const T &X, FoldingSetNodeID &ID) {
- ID.AddInteger(static_cast<std::underlying_type_t<T>>(X));
+ ID.AddInteger(llvm::to_underlying(X));
}
};
More information about the llvm-commits
mailing list