Author: Timm Baeder Date: 2026-10-15T11:49:12+02:00 New Revision: 9df29523000356879ec679e984458f36f7a35965
URL: https://github.com/llvm/llvm-project/commit/9df29523000356879ec679e984458f36f7a35965 DIFF: https://github.com/llvm/llvm-project/commit/9df29523000356879ec679e984458f36f7a35965.diff LOG: [clang][bytecode][NFC] Simplify bytecode emission (#232215) Remove unused parameters and switch to returning the success boolean instead of writing to a reference parameter. Added: Modified: clang/lib/AST/ByteCode/ByteCodeEmitter.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp index 2b2e6be3bdce2..e55bfb586fb7b 100644 --- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp +++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp @@ -130,8 +130,7 @@ int32_t ByteCodeEmitter::getOffset(LabelTy Label) { /// Helper to write bytecode and bail out if 32-bit offsets become invalid. template <typename T> -static void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, - const T &Val, bool &Success) { +static bool emit(llvm::SmallVectorImpl<std::byte> &Code, const T &Val) { size_t ValPos = Code.size(); size_t Size; @@ -140,10 +139,8 @@ static void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, else Size = align(sizeof(T)); - if (ValPos + Size > std::numeric_limits<unsigned>::max()) { - Success = false; - return; - } + if (ValPos + Size > std::numeric_limits<unsigned>::max()) + return false; // Access must be aligned! assert(aligned(ValPos)); @@ -154,20 +151,19 @@ static void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, new (Code.data() + ValPos) uintptr_t(reinterpret_cast<uintptr_t>(Val)); else new (Code.data() + ValPos) T(Val); + return true; } /// Emits a serializable value. These usually (potentially) contain /// heap-allocated memory and aren't trivially copyable. template <typename T> -static void emitSerialized(llvm::SmallVectorImpl<std::byte> &Code, const T &Val, - bool &Success) { +static bool emitSerialized(llvm::SmallVectorImpl<std::byte> &Code, + const T &Val) { size_t ValPos = Code.size(); size_t Size = align(Val.bytesToSerialize()); - if (ValPos + Size > std::numeric_limits<unsigned>::max()) { - Success = false; - return; - } + if (ValPos + Size > std::numeric_limits<unsigned>::max()) + return false; // Access must be aligned! assert(aligned(ValPos)); @@ -175,46 +171,41 @@ static void emitSerialized(llvm::SmallVectorImpl<std::byte> &Code, const T &Val, Code.resize_for_overwrite(ValPos + Size); Val.serialize(Code.data() + ValPos); + return true; } template <> -void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, - const Floating &Val, bool &Success) { - emitSerialized(Code, Val, Success); +bool emit(llvm::SmallVectorImpl<std::byte> &Code, const Floating &Val) { + return emitSerialized(Code, Val); } template <> -void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, - const IntegralAP<false> &Val, bool &Success) { - emitSerialized(Code, Val, Success); +bool emit(llvm::SmallVectorImpl<std::byte> &Code, + const IntegralAP<false> &Val) { + return emitSerialized(Code, Val); } template <> -void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, - const IntegralAP<true> &Val, bool &Success) { - emitSerialized(Code, Val, Success); +bool emit(llvm::SmallVectorImpl<std::byte> &Code, const IntegralAP<true> &Val) { + return emitSerialized(Code, Val); } template <> -void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code, - const FixedPoint &Val, bool &Success) { - emitSerialized(Code, Val, Success); +bool emit(llvm::SmallVectorImpl<std::byte> &Code, const FixedPoint &Val) { + return emitSerialized(Code, Val); } template <typename... Tys> bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args, SourceInfo SI) { - bool Success = true; - // The opcode is followed by arguments. The source info is // attached to the address after the opcode. - emit(P, Code, Op, Success); + emit(Code, Op); SI = LocOverride.value_or(SI); if (SrcMap.empty() || SrcMap.back() != SI) SrcMap.push(Code.size(), SI); - (..., emit(P, Code, Args, Success)); - return Success; + return (emit(Code, Args) && ...); } bool ByteCodeEmitter::jumpTrue(const LabelTy &Label, SourceInfo SI) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
