9class UseAfterLifetimeEnd :
public Checker<check::EndFunction> {
11 void reportDanglingSource(
const MemRegion *Source, ExplodedNode *N,
12 CheckerContext &
C)
const;
13 void checkEndFunction(
const ReturnStmt *RS, CheckerContext &
C)
const;
14 const BugType BugMsg{
this,
"UseAfterLifetimeEnd",
"LifetimeBound"};
19void UseAfterLifetimeEnd::checkEndFunction(
const ReturnStmt *RS,
31 SVal RetVal =
C.getSVal(RetExpr);
33 std::vector<const MemRegion *> RetValRegion =
35 if (RetValRegion.empty())
39 C.generateNonFatalErrorNode(State,
C.getPredecessor())) {
40 for (
const MemRegion *R : RetValRegion)
41 reportDanglingSource(R, N,
C);
45void UseAfterLifetimeEnd::reportDanglingSource(
const MemRegion *Source,
47 CheckerContext &
C)
const {
48 auto BR = std::make_unique<PathSensitiveBugReport>(
50 (llvm::Twine(
"Returning value bound to '") + Source->
getString() +
51 "' that will go out of scope"),
53 C.emitReport(std::move(BR));
56void ento::registerUseAfterLifetimeEnd(CheckerManager &Mgr) {
60bool ento::shouldRegisterUseAfterLifetimeEnd(
const CheckerManager &Mgr) {
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
std::string getString() const
Get a string representation of a region for debug use.
std::vector< const MemRegion * > getDanglingRegionsAfterReturn(SVal Source, ProgramStateRef State, CheckerContext &C)
Returns the set of lifetime sources bound to Source that are dangling stack regions.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.