This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Use placement new to construct opcode arguments into bytecode vector
ClosedPublic

Authored by tbaeder on Nov 23 2022, 1:56 AM.

Details

Summary

This is split-out from https://reviews.llvm.org/D134859 as it showed up there.

When the opcode argument is not trivially copyable, we can't just memcpy it into our code vector. Use placement new to copy it instead.

This is currently dead code without https://reviews.llvm.org/D134859.

Diff Detail

Event Timeline

tbaeder created this revision.Nov 23 2022, 1:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2022, 1:56 AM
tbaeder requested review of this revision.Nov 23 2022, 1:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2022, 1:56 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sepavloff added inline comments.Nov 23 2022, 7:38 AM
clang/lib/AST/Interp/ByteCodeEmitter.cpp
164–167

Do we really need a separate case for trivially copyable types?

tbaeder added inline comments.Nov 23 2022, 8:00 AM
clang/lib/AST/Interp/ByteCodeEmitter.cpp
164–167

It's not necessary, placement new'ing all everything works. I was just trying to keep the old behavior as much as possible.

sepavloff added inline comments.Nov 23 2022, 10:21 AM
clang/lib/AST/Interp/ByteCodeEmitter.cpp
164–167

Another thing: when copy constructor for APFloat works, it can allocate data in heap. So the serialization is not perfect in this case. Would it be suitable for the interpretator?

tbaeder added inline comments.Nov 23 2022, 11:00 PM
clang/lib/AST/Interp/ByteCodeEmitter.cpp
164–167

That heap allocation is exactly why this change exists. I know it's not serialized here, but that's not a problem (right now at leat), since we don't write the byte code to disk.

sepavloff accepted this revision.Nov 24 2022, 1:33 AM

LGTM.

I would propose not to have a special case for trivially copyable types, if that is possible.

This revision is now accepted and ready to land.Nov 24 2022, 1:33 AM
aaron.ballman accepted this revision.Nov 28 2022, 2:29 PM
This revision was landed with ongoing or failed builds.Nov 30 2022, 1:34 AM
This revision was automatically updated to reflect the committed changes.