stripComments(cook(...)) is a common pattern being written.
Without this patch, this has a use-after-free issue (cook returns a temporary
TokenStream object which has its own payload, but the payload is not
shared with the one returned by stripComments).
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
cook is more tricky, it takes a TokenStream, and returns a new one with an allocator payload:
- the input TokenStream doesn't have a payload, this is OK
- the input TokenStream has a payload, but what if the type of payload is not an allocator?
Possible solution: 1) always assert the input TokenStream doesn't have a payload or the payload is allocator type 2) merge the lex and cook function, it looks like we always use the cook one.
Comment Actions
Payload is opaque, it can be a pair of {new payload, inner payload}. e.g.
void TokenStream::addPayload(shared_ptr<void> P) { Payload = make_shared<pair<shared_ptr<void>, shared_ptr<void>>>(std::move(P), std::move(Payload)); }