Author: Timm Bäder Date: 2022-09-29T12:50:55+02:00 New Revision: 1c35f3b93aff7c39832f42f470c45fd24c3a779c
URL: https://github.com/llvm/llvm-project/commit/1c35f3b93aff7c39832f42f470c45fd24c3a779c DIFF: https://github.com/llvm/llvm-project/commit/1c35f3b93aff7c39832f42f470c45fd24c3a779c.diff LOG: [clang][Interp][NFC] Unify emit() implementations Instead of two overloads, use a if constexpr to differentiate between pointer and non-pointer parameters Added: Modified: clang/lib/AST/Interp/ByteCodeEmitter.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 42a3ab7837f9..20e054ab87df 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -129,30 +129,28 @@ bool ByteCodeEmitter::bail(const SourceLocation &Loc) { /// Helper to write bytecode and bail out if 32-bit offsets become invalid. /// Pointers will be automatically marshalled as 32-bit IDs. template <typename T> -static std::enable_if_t<!std::is_pointer<T>::value, void> -emit(Program &P, std::vector<char> &Code, const T &Val, bool &Success) { - size_t Size = sizeof(Val); - if (Code.size() + Size > std::numeric_limits<unsigned>::max()) { - Success = false; - return; - } +static void emit(Program &P, std::vector<char> &Code, const T &Val, + bool &Success) { + size_t Size; - const char *Data = reinterpret_cast<const char *>(&Val); - Code.insert(Code.end(), Data, Data + Size); -} + if constexpr (std::is_pointer_v<T>) + Size = sizeof(uint32_t); + else + Size = sizeof(T); -template <typename T> -static std::enable_if_t<std::is_pointer<T>::value, void> -emit(Program &P, std::vector<char> &Code, const T &Val, bool &Success) { - size_t Size = sizeof(uint32_t); if (Code.size() + Size > std::numeric_limits<unsigned>::max()) { Success = false; return; } - uint32_t ID = P.getOrCreateNativePointer(Val); - const char *Data = reinterpret_cast<const char *>(&ID); - Code.insert(Code.end(), Data, Data + Size); + if constexpr (!std::is_pointer_v<T>) { + const char *Data = reinterpret_cast<const char *>(&Val); + Code.insert(Code.end(), Data, Data + Size); + } else { + uint32_t ID = P.getOrCreateNativePointer(Val); + const char *Data = reinterpret_cast<const char *>(&ID); + Code.insert(Code.end(), Data, Data + Size); + } } template <typename... Tys> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits