[PATCH] D138554: [clang][Interp] Use placement new to construct opcode arguments into bytecode vector

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 30 01:34:22 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaaf73ae266db: [clang][Interp] Use placement new to construct opcode args into vector (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D138554?vs=477420&id=478852#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138554/new/

https://reviews.llvm.org/D138554

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp


Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -161,8 +161,10 @@
   }
 
   if constexpr (!std::is_pointer_v<T>) {
-    const char *Data = reinterpret_cast<const char *>(&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<const char *>(&ID);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138554.478852.patch
Type: text/x-patch
Size: 686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221130/e60bdedc/attachment.bin>


More information about the cfe-commits mailing list