From 1c35f3b93aff7c39832f42f470c45fd24c3a779c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Tue, 27 Sep 2022 07:29:09 +0200 Subject: [PATCH] [clang][Interp][NFC] Unify emit() implementations Instead of two overloads, use a if constexpr to differentiate between pointer and non-pointer parameters --- clang/lib/AST/Interp/ByteCodeEmitter.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 42a3ab7..20e054a 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 -static std::enable_if_t::value, void> -emit(Program &P, std::vector &Code, const T &Val, bool &Success) { - size_t Size = sizeof(Val); - if (Code.size() + Size > std::numeric_limits::max()) { - Success = false; - return; - } +static void emit(Program &P, std::vector &Code, const T &Val, + bool &Success) { + size_t Size; - const char *Data = reinterpret_cast(&Val); - Code.insert(Code.end(), Data, Data + Size); -} + if constexpr (std::is_pointer_v) + Size = sizeof(uint32_t); + else + Size = sizeof(T); -template -static std::enable_if_t::value, void> -emit(Program &P, std::vector &Code, const T &Val, bool &Success) { - size_t Size = sizeof(uint32_t); if (Code.size() + Size > std::numeric_limits::max()) { Success = false; return; } - uint32_t ID = P.getOrCreateNativePointer(Val); - const char *Data = reinterpret_cast(&ID); - Code.insert(Code.end(), Data, Data + Size); + if constexpr (!std::is_pointer_v) { + const char *Data = reinterpret_cast(&Val); + Code.insert(Code.end(), Data, Data + Size); + } else { + uint32_t ID = P.getOrCreateNativePointer(Val); + const char *Data = reinterpret_cast(&ID); + Code.insert(Code.end(), Data, Data + Size); + } } template -- 2.7.4