This is an archive of the discontinued LLVM Phabricator instance.

[ORC] fix use-after-free detected by -Wreturn-stack-address
ClosedPublic

Authored by mgehre on Aug 19 2019, 2:13 PM.

Details

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]].

Diff Detail

Repository
rL LLVM

Event Timeline

mgehre created this revision.Aug 19 2019, 2:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2019, 2:13 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
lhames accepted this revision.Aug 19 2019, 2:50 PM

LGTM. Nice catch!

This revision is now accepted and ready to land.Aug 19 2019, 2:50 PM
This revision was automatically updated to reflect the committed changes.