From 665ea96bb51b06b05d18eddd5fd938f5a536e28a Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Mon, 19 Aug 2019 21:59:44 +0000 Subject: [PATCH] [ORC] fix use-after-free detected by -Wreturn-stack-address Summary: 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]]`. Reviewers: lhames, sgraenitz Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66440 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369306 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/Orc/Layer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExecutionEngine/Orc/Layer.cpp b/lib/ExecutionEngine/Orc/Layer.cpp index ba2ec32da78..580e2682ec8 100644 --- a/lib/ExecutionEngine/Orc/Layer.cpp +++ b/lib/ExecutionEngine/Orc/Layer.cpp @@ -51,7 +51,7 @@ IRMaterializationUnit::IRMaterializationUnit( StringRef IRMaterializationUnit::getName() const { if (TSM) return TSM.withModuleDo( - [](const Module &M) { return M.getModuleIdentifier(); }); + [](const Module &M) -> StringRef { return M.getModuleIdentifier(); }); return ""; } -- 2.40.0