[ORC] fix use-after-free detected by -Wreturn-stack-address
authorMatthias Gehre <M.Gehre@gmx.de>
Mon, 19 Aug 2019 21:59:44 +0000 (21:59 +0000)
committerMatthias Gehre <M.Gehre@gmx.de>
Mon, 19 Aug 2019 21:59:44 +0000 (21:59 +0000)
commit5b3275e56f3c8e1b3cbc15f3866d903b9275c132
treef1926504a23f7c1af3c6456e4f25f07b109b58e5
parent8b962f2814999e1cf48e964096fb9b657ba5b6eb
[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

llvm-svn: 369306
llvm/lib/ExecutionEngine/Orc/Layer.cpp