Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -313,7 +313,8 @@ bool HandleBinding(StoreManager &SMgr, Store S, const MemRegion *Region, SVal Val) override { - if (!isa(Region->getMemorySpace())) + const MemSpaceRegion * MemSpace = Region->getMemorySpace(); + if (isa(MemSpace) && !isNotInCurrentFrame(MemSpace, Ctx)) return true; const MemRegion *VR = Val.getAsRegion(); if (VR && isa(VR->getMemorySpace()) && @@ -338,8 +339,8 @@ if (!BT_stackleak) BT_stackleak = std::make_unique( CheckNames[CK_StackAddrEscapeChecker], - "Stack address stored into global variable", - "Stack address was saved into a global variable. " + "Stack address leaked", + "Address from the current stack frame is saved in a variable outside of the stack frame. " "This is dangerous because the address will become " "invalid after returning from the function"); @@ -350,10 +351,13 @@ SourceRange Range = genName(Out, P.second, Ctx.getASTContext()); Out << " is still referred to by the "; if (isa(P.first->getMemorySpace())) - Out << "static"; - else - Out << "global"; - Out << " variable '"; + Out << "static variable '"; + else if (isa(P.first->getMemorySpace())) + Out << "global variable '"; + else if (isa(P.first->getMemorySpace())) + Out << "dynamically allocated variable '"; + else if (isa(P.first->getMemorySpace())) + Out << "local variable from another function '"; const VarRegion *VR = cast(P.first->getBaseRegion()); Out << *VR->getDecl() << "' upon returning to the caller. This will be a dangling reference";