[PATCH] D125311: [pseudo] Share the underly payload when stripping comments for a token stream
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 10 05:53:18 PDT 2022
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang-tools-extra.
`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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125311
Files:
clang-tools-extra/pseudo/include/clang-pseudo/Token.h
clang-tools-extra/pseudo/lib/Token.cpp
Index: clang-tools-extra/pseudo/lib/Token.cpp
===================================================================
--- clang-tools-extra/pseudo/lib/Token.cpp
+++ clang-tools-extra/pseudo/lib/Token.cpp
@@ -116,7 +116,7 @@
}
TokenStream stripComments(const TokenStream &Input) {
- TokenStream Out;
+ TokenStream Out(Input.getPayload());
for (const Token &T : Input.tokens()) {
if (T.Kind == tok::comment)
continue;
Index: clang-tools-extra/pseudo/include/clang-pseudo/Token.h
===================================================================
--- clang-tools-extra/pseudo/include/clang-pseudo/Token.h
+++ clang-tools-extra/pseudo/include/clang-pseudo/Token.h
@@ -161,6 +161,9 @@
return Storage[1];
}
+ /// Returns the shared payload.
+ std::shared_ptr<void> getPayload() const { return Payload; }
+
/// Print the tokens in this stream to the output stream.
///
/// The presence of newlines/spaces is preserved, but not the quantity.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125311.428354.patch
Type: text/x-patch
Size: 973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220510/d2bae341/attachment.bin>
More information about the cfe-commits
mailing list