This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] WIP: Array fillers
AbandonedPublic

Authored by tbaeder on Sep 13 2022, 12:40 AM.

Details

Summary

Uploading this now to get some early feedback on the approach and maybe find some better tests.

Pointers in the VM are implemented through the Pointer class. Each Pointer points to a Block, which represent memory. However, each Block also knows all the Pointers pointing at it. I've used this to find simply replace a Block representing an array with a larger one and update all pointers pointing to said block (Block::transferPointers()). This is the core of it all, but it requires quite a few smaller changes that could be broken out of this patch of course. Like enabling pointer tracking for static Blocks.

Diff Detail

Event Timeline

tbaeder created this revision.Sep 13 2022, 12:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2022, 12:40 AM
tbaeder requested review of this revision.Sep 13 2022, 12:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2022, 12:40 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder added inline comments.Sep 14 2022, 3:59 AM
clang/lib/AST/Interp/Context.cpp
54

The additional asserts I inserted here could be in another patch. However, I added them because I ran into a peculiar problem: when creating a Pointer, it calls Pointee->addPointer(this). It will only remove itself from the pointee again in its destructor. But the destructor is not (necessarily) being called at all because the Pointer is constructed in the stack (or otherwise placement-new'ed into a larger memory region).

clang/lib/AST/Interp/Interp.h
831

Note here that both the block and the descriptor are leaked. They are usually allocated in Program, which uses its own allocator for them. I'm not 100% sure what to do about this, since the blocks have different lifetimes depending on if they are for global or local variables (or parameters).
Short of introducing a Program::managesBlock(Block* B) that just does a linear search for the blocks.

tbaeder updated this revision to Diff 460059.Sep 14 2022, 6:15 AM
shafik added inline comments.Oct 13 2022, 5:02 PM
clang/lib/AST/Interp/Descriptor.h
83

How about NumElemsWithFiller?

clang/lib/AST/Interp/Pointer.h
252

You say greater here but you use < below in the assert instead of <=

tbaeder abandoned this revision.Sep 5 2023, 2:03 AM