From 2283ffcf11af4c631e52f47c539d65307f450598 Mon Sep 17 00:00:00 2001 From: Sean Eveson Date: Thu, 26 May 2016 14:02:17 +0000 Subject: [PATCH] [Analyzer] Correct stack address escape diagnostic Summary: Leaking a stack address via a static variable refers to it in the diagnostic as a 'global'. This patch corrects the diagnostic for static variables. Patch by Phil Camp, SN Systems Reviewers: dcoughlin, zaks.anna Subscribers: xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D19866 Patch by Phil Camp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270849 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp | 7 ++++++- test/Analysis/stackaddrleak.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index 79fc701d6d..556274d0ed 100644 --- a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -236,7 +236,12 @@ void StackAddrEscapeChecker::checkEndFunction(CheckerContext &Ctx) const { SmallString<512> buf; llvm::raw_svector_ostream os(buf); SourceRange range = genName(os, cb.V[i].second, Ctx.getASTContext()); - os << " is still referred to by the global variable '"; + os << " is still referred to by the "; + if (isa(cb.V[i].first->getMemorySpace())) + os << "static"; + else + os << "global"; + os << " variable '"; const VarRegion *VR = cast(cb.V[i].first->getBaseRegion()); os << *VR->getDecl() << "' upon returning to the caller. This will be a dangling reference"; diff --git a/test/Analysis/stackaddrleak.c b/test/Analysis/stackaddrleak.c index 21a15d75ec..717f30964a 100644 --- a/test/Analysis/stackaddrleak.c +++ b/test/Analysis/stackaddrleak.c @@ -19,7 +19,7 @@ void f2() { p = (const char *) __builtin_alloca(12); } // expected-warning{{Address of stack memory allocated by call to alloca() on line 19 is still referred to by the global variable 'p' upon returning to the caller. This will be a dangling reference}} -// PR 7383 - previosly the stack address checker would crash on this example +// PR 7383 - previously the stack address checker would crash on this example // because it would attempt to do a direct load from 'pr7383_list'. static int pr7383(__const char *__) { @@ -33,7 +33,7 @@ void test_multi_return() { int x; a = &x; b = &x; -} // expected-warning{{Address of stack memory associated with local variable 'x' is still referred to by the global variable 'a' upon returning}} expected-warning{{Address of stack memory associated with local variable 'x' is still referred to by the global variable 'b' upon returning}} +} // expected-warning{{Address of stack memory associated with local variable 'x' is still referred to by the static variable 'a' upon returning}} expected-warning{{Address of stack memory associated with local variable 'x' is still referred to by the static variable 'b' upon returning}} intptr_t returnAsNonLoc() { int x; -- 2.40.0