[PATCH] D66440: [ORC] fix use-after-free detected by -Wreturn-stack-address
Matthias Gehre via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 14:13:22 PDT 2019
mgehre created this revision.
mgehre added reviewers: lhames, sgraenitz.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
llvm/lib/ExecutionEngine/Orc/Layer.cpp:53:12: warning: returning address of local temporary object [-Wreturn-stack-address]
In
StringRef IRMaterializationUnit::getName() const {
[...]
return TSM.withModuleDo(
[](const Module &M) { return M.getModuleIdentifier(); });
`getModuleIdentifier()` returns a `const std::string &`, but the implicit return type
of the lambda is `std::string` by value, and thus the returned `StringRef` refers
to a temporary `std::string`.
Detect by annotating `llvm::StringRef` with `[[gsl::Pointer]]`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66440
Files:
llvm/lib/ExecutionEngine/Orc/Layer.cpp
Index: llvm/lib/ExecutionEngine/Orc/Layer.cpp
===================================================================
--- llvm/lib/ExecutionEngine/Orc/Layer.cpp
+++ llvm/lib/ExecutionEngine/Orc/Layer.cpp
@@ -51,7 +51,7 @@
StringRef IRMaterializationUnit::getName() const {
if (TSM)
return TSM.withModuleDo(
- [](const Module &M) { return M.getModuleIdentifier(); });
+ [](const Module &M) -> StringRef { return M.getModuleIdentifier(); });
return "<null module>";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66440.215983.patch
Type: text/x-patch
Size: 491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190819/d2c9ceda/attachment.bin>
More information about the llvm-commits
mailing list