r273340 - [analyzer] Teach trackNullOrUndefValue() about class property accessors.
Devin Coughlin via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 21 17:20:00 PDT 2016
Author: dcoughlin
Date: Tue Jun 21 19:20:00 2016
New Revision: 273340
URL: http://llvm.org/viewvc/llvm-project?rev=273340&view=rev
Log:
[analyzer] Teach trackNullOrUndefValue() about class property accessors.
Teach trackNullOrUndefValue() how to properly look through PseudoObjectExprs
to find the underlying semantic method call for property getters. This fixes a
crash when looking through class property getters that I introduced in r265839.
rdar://problem/26796666
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/inlining/false-positive-suppression.m
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=273340&r1=273339&r2=273340&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Jun 21 19:20:00 2016
@@ -914,7 +914,10 @@ static const Expr *peelOffOuterExpr(cons
if (auto *POE = dyn_cast<PseudoObjectExpr>(Ex)) {
auto *PropRef = dyn_cast<ObjCPropertyRefExpr>(POE->getSyntacticForm());
if (PropRef && PropRef->isMessagingGetter()) {
- return peelOffOuterExpr(POE->getSemanticExpr(1), N);
+ const Expr *GetterMessageSend =
+ POE->getSemanticExpr(POE->getNumSemanticExprs() - 1);
+ assert(isa<ObjCMessageExpr>(GetterMessageSend));
+ return peelOffOuterExpr(GetterMessageSend, N);
}
}
Modified: cfe/trunk/test/Analysis/inlining/false-positive-suppression.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/false-positive-suppression.m?rev=273340&r1=273339&r2=273340&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/false-positive-suppression.m (original)
+++ cfe/trunk/test/Analysis/inlining/false-positive-suppression.m Tue Jun 21 19:20:00 2016
@@ -49,6 +49,12 @@ __attribute__((objc_root_class))
@end
+ at interface SubOfSomeClass : SomeClass
+ at end
+
+ at implementation SubOfSomeClass
+ at end
+
@implementation SomeClass
-(int *)methodReturningNull {
return 0;
@@ -57,6 +63,10 @@ __attribute__((objc_root_class))
-(int *)propertyReturningNull {
return 0;
}
+
++(int *)classPropertyReturningNull {
+ return 0;
+}
@end
void testMethodReturningNull(SomeClass *sc) {
@@ -72,6 +82,24 @@ void testPropertyReturningNull(SomeClass
*result = 1;
#ifndef SUPPRESSED
// expected-warning at -2 {{Dereference of null pointer}}
+#endif
+}
+
+ at implementation SubOfSomeClass (ForTestOfSuperProperty)
+-(void)testSuperPropertyReturningNull {
+ int *result = super.propertyReturningNull;
+ *result = 1;
+#ifndef SUPPRESSED
+ // expected-warning at -2 {{Dereference of null pointer}}
+#endif
+}
+ at end
+
+void testClassPropertyReturningNull() {
+ int *result = SomeClass.classPropertyReturningNull;
+ *result = 1;
+#ifndef SUPPRESSED
+ // expected-warning at -2 {{Dereference of null pointer}}
#endif
}
More information about the cfe-commits
mailing list