Author: Kazu Hirata Date: 2025-09-10T08:36:55-07:00 New Revision: 9a64fa7b7e446651bf40fe0e1289505bc115c6dd
URL: https://github.com/llvm/llvm-project/commit/9a64fa7b7e446651bf40fe0e1289505bc115c6dd DIFF: https://github.com/llvm/llvm-project/commit/9a64fa7b7e446651bf40fe0e1289505bc115c6dd.diff LOG: [Support] Use CTLog2 from PointerLikeTypeTraits.h (NFC) (#157790) This patch replaces ConstantLog2 with CTLog2. ConstantLog2 only operates on alignment values, making the two interchangeable in this context. CTLog2 also has the benefit of a static_assert that ensures its parameter is a power of two. Added: Modified: clang/include/clang/AST/Expr.h llvm/include/llvm/Support/PointerLikeTypeTraits.h Removed: ################################################################################ diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 23a0996f02725..d2b872458ae82 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1038,7 +1038,7 @@ class Expr : public ValueStmt { // PointerLikeTypeTraits is specialized so it can be used with a forward-decl of // Expr. Verify that we got it right. static_assert(llvm::PointerLikeTypeTraits<Expr *>::NumLowBitsAvailable <= - llvm::detail::ConstantLog2<alignof(Expr)>::value, + llvm::CTLog2<alignof(Expr)>(), "PointerLikeTypeTraits<Expr*> assumes too much alignment."); using ConstantExprKind = Expr::ConstantExprKind; diff --git a/llvm/include/llvm/Support/PointerLikeTypeTraits.h b/llvm/include/llvm/Support/PointerLikeTypeTraits.h index 1b15f930bd87d..0ac919fd9c0b9 100644 --- a/llvm/include/llvm/Support/PointerLikeTypeTraits.h +++ b/llvm/include/llvm/Support/PointerLikeTypeTraits.h @@ -15,8 +15,8 @@ #define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H #include "llvm/Support/DataTypes.h" +#include "llvm/Support/MathExtras.h" #include <cassert> -#include <type_traits> namespace llvm { @@ -25,12 +25,6 @@ namespace llvm { template <typename T> struct PointerLikeTypeTraits; namespace detail { -/// A tiny meta function to compute the log2 of a compile time constant. -template <size_t N> -struct ConstantLog2 - : std::integral_constant<size_t, ConstantLog2<N / 2>::value + 1> {}; -template <> struct ConstantLog2<1> : std::integral_constant<size_t, 0> {}; - // Provide a trait to check if T is pointer-like. template <typename T, typename U = void> struct HasPointerLikeTypeTraits { static const bool value = false; @@ -57,8 +51,7 @@ template <typename T> struct PointerLikeTypeTraits<T *> { static inline void *getAsVoidPointer(T *P) { return P; } static inline T *getFromVoidPointer(void *P) { return static_cast<T *>(P); } - static constexpr int NumLowBitsAvailable = - detail::ConstantLog2<alignof(T)>::value; + static constexpr int NumLowBitsAvailable = CTLog2<alignof(T)>(); }; template <> struct PointerLikeTypeTraits<void *> { @@ -123,8 +116,7 @@ template <> struct PointerLikeTypeTraits<uintptr_t> { /// potentially use alignment attributes on functions to satisfy that. template <int Alignment, typename FunctionPointerT> struct FunctionPointerLikeTypeTraits { - static constexpr int NumLowBitsAvailable = - detail::ConstantLog2<Alignment>::value; + static constexpr int NumLowBitsAvailable = CTLog2<Alignment>(); static inline void *getAsVoidPointer(FunctionPointerT P) { assert((reinterpret_cast<uintptr_t>(P) & ~((uintptr_t)-1 << NumLowBitsAvailable)) == 0 && _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits