summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2016-10-31 21:04:54 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2016-10-31 21:04:54 +0000
commita21df23fd81fa208a69e2b4215f42c18809eaed8 (patch)
tree560a01fb00764284116845be0bbca57daf695af6 /clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
parent56e6135774ac0b8c696f094a24282dc197013f1d (diff)
downloadbcm5719-llvm-a21df23fd81fa208a69e2b4215f42c18809eaed8.tar.gz
bcm5719-llvm-a21df23fd81fa208a69e2b4215f42c18809eaed8.zip
[analyzer] MacOSXAPIChecker: Improve warnings for __block vars in dispatch_once.
The checker already warns for __block-storage variables being used as a dispatch_once() predicate, however it refers to them as local which is not quite accurate, so we fix that. Differential Revision: https://reviews.llvm.org/D26159 llvm-svn: 285637
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
index c2a54baa927..0e0f52af316 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
@@ -94,10 +94,15 @@ void MacOSXAPIChecker::CheckDispatchOnce(CheckerContext &C, const CallExpr *CE,
bool SuggestStatic = false;
os << "Call to '" << FName << "' uses";
if (const VarRegion *VR = dyn_cast<VarRegion>(RB)) {
- // We filtered out globals earlier, so it must be a local variable.
+ // We filtered out globals earlier, so it must be a local variable
+ // or a block variable which is under UnknownSpaceRegion.
if (VR != R)
os << " memory within";
- os << " the local variable '" << VR->getDecl()->getName() << '\'';
+ if (VR->getDecl()->hasAttr<BlocksAttr>())
+ os << " the block variable '";
+ else
+ os << " the local variable '";
+ os << VR->getDecl()->getName() << '\'';
SuggestStatic = true;
} else if (const ObjCIvarRegion *IVR = getParentIvarRegion(R)) {
if (IVR != R)
@@ -108,6 +113,9 @@ void MacOSXAPIChecker::CheckDispatchOnce(CheckerContext &C, const CallExpr *CE,
} else if (isa<UnknownSpaceRegion>(RS)) {
// Presence of an IVar superregion has priority over this branch, because
// ObjC objects are on the heap even if the core doesn't realize this.
+ // Presence of a block variable base region has priority over this branch,
+ // because block variables are known to be either on stack or on heap
+ // (might actually move between the two, hence UnknownSpace).
return;
} else {
os << " stack allocated memory";
OpenPOWER on IntegriCloud