diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -161,8 +161,10 @@ } if constexpr (!std::is_pointer_v) { - const char *Data = reinterpret_cast(&Val); - Code.insert(Code.end(), Data, Data + Size); + // Construct the value directly into our storage vector. + size_t ValPos = Code.size(); + Code.resize(Code.size() + Size); + new (Code.data() + ValPos) T(Val); } else { uint32_t ID = P.getOrCreateNativePointer(Val); const char *Data = reinterpret_cast(&ID);