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.
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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits