Skip to content

Commit aaf73ae

Browse files
committed
[clang][Interp] Use placement new to construct opcode args into vector
This way we're invoking the copy constructor, which might be necessary if the argument is not trivially constructible. Differential Revision: https://reviews.llvm.org/D138554
1 parent c3380c3 commit aaf73ae

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ static void emit(Program &P, std::vector<char> &Code, const T &Val,
161161
}
162162

163163
if constexpr (!std::is_pointer_v<T>) {
164-
const char *Data = reinterpret_cast<const char *>(&Val);
165-
Code.insert(Code.end(), Data, Data + Size);
164+
// Construct the value directly into our storage vector.
165+
size_t ValPos = Code.size();
166+
Code.resize(Code.size() + Size);
167+
new (Code.data() + ValPos) T(Val);
166168
} else {
167169
uint32_t ID = P.getOrCreateNativePointer(Val);
168170
const char *Data = reinterpret_cast<const char *>(&ID);

0 commit comments

Comments
 (0)