summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-09-28 22:21:35 +0000
committerJordan Rose <jordan_rose@apple.com>2012-09-28 22:21:35 +0000
commit657b5f464d8c91935f46e69dde2f13e97cdb51de (patch)
tree9209a8e92a8faf067e994bc410ef68e4a0212196 /clang/lib/Sema/AnalysisBasedWarnings.cpp
parentd393458c3316257e5c4bf9dfdb9ace8c426edce8 (diff)
downloadbcm5719-llvm-657b5f464d8c91935f46e69dde2f13e97cdb51de.tar.gz
bcm5719-llvm-657b5f464d8c91935f46e69dde2f13e97cdb51de.zip
-Warc-repeated-use-of-weak: check ivars and variables as well.
Like properties, loading from a weak ivar twice in the same function can give you inconsistent results if the object is deallocated between the two loads. It is safer to assign to a strong local variable and use that. Second half of <rdar://problem/12280249>. llvm-svn: 164855
Diffstat (limited to 'clang/lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r--clang/lib/Sema/AnalysisBasedWarnings.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 86e9dc2d648..bc25c0a5548 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -957,19 +957,42 @@ static void diagnoseRepeatedUseOfWeak(Sema &S,
const WeakObjectProfileTy &Key = I->second->first;
const WeakUseVector &Uses = I->second->second;
- // For complicated expressions like self.foo.bar, it's hard to keep track
- // of whether 'self.foo' is the same between two cases. We can only be
- // 100% sure of a repeated use if the "base" part of the key is a variable,
- // rather than, say, another property.
+ // For complicated expressions like 'a.b.c' and 'x.b.c', WeakObjectProfileTy
+ // may not contain enough information to determine that these are different
+ // properties. We can only be 100% sure of a repeated use in certain cases,
+ // and we adjust the diagnostic kind accordingly so that the less certain
+ // case can be turned off if it is too noisy.
unsigned DiagKind;
if (Key.isExactProfile())
DiagKind = diag::warn_arc_repeated_use_of_weak;
else
DiagKind = diag::warn_arc_possible_repeated_use_of_weak;
+ // Classify the weak object being accessed for better warning text.
+ // This enum should stay in sync with the cases in
+ // warn_arc_repeated_use_of_weak and warn_arc_possible_repeated_use_of_weak.
+ enum {
+ Variable,
+ Property,
+ ImplicitProperty,
+ Ivar
+ } ObjectKind;
+
+ const NamedDecl *D = Key.getProperty();
+ if (isa<VarDecl>(D))
+ ObjectKind = Variable;
+ else if (isa<ObjCPropertyDecl>(D))
+ ObjectKind = Property;
+ else if (isa<ObjCMethodDecl>(D))
+ ObjectKind = ImplicitProperty;
+ else if (isa<ObjCIvarDecl>(D))
+ ObjectKind = Ivar;
+ else
+ llvm_unreachable("Unexpected weak object kind!");
+
// Show the first time the object was read.
S.Diag(FirstRead->getLocStart(), DiagKind)
- << FunctionKind
+ << ObjectKind << D << FunctionKind
<< FirstRead->getSourceRange();
// Print all the other accesses as notes.
OpenPOWER on IntegriCloud